Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions README.md

This file was deleted.

10 changes: 10 additions & 0 deletions check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

function validateForm()
{
var x = document.forms["searchform"]["moviename"].value;
if (x == "") {
alert( "All fields are mandatory" );
return false ;
}
return true ;
}
34 changes: 34 additions & 0 deletions display.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<?php
session_start();
if(isset($_SESSION['results_array']))
{
$results_arr = $_SESSION['results_array'];
if(count($results_arr)>=1)
{
echo '<table id="customers">';
echo '<tr>';
echo '<th>Movies</th>';
echo '</tr>';

for($i=0; $i<count($results_arr); $i++)
{
if($i % 2)
echo '<tr><td>'.$results_arr[$i].'</td></tr>';
else
echo '<tr class="alt"><td>'.$results_arr[$i].'</td></tr>';
}
echo '</table>';
}
else
{
echo 'There are not movies.';
}
}
?>

</html>
28 changes: 28 additions & 0 deletions form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="check.js"></script>

</head>

<form name="searchform" action="search_movie.php" method="post" onsubmit="return validateForm();">
<fieldset class="search-info">
<label>
<h3> Search Movie</h3>
<input id="moviename" type="text" name="moviename" value="" placeholder="movie name"/><br>
<select id="category" name="category">
<option selected="selected" value="comedy">Comedy</option>
<option value="horror">Horror</option>
<option value="drama">Drama</option>
</select>
</label>

</fieldset>
<fieldset class="search-action">
<input class="btn" type="submit" name="search" value="Search">

</fieldset>
</form>


</html>
7 changes: 7 additions & 0 deletions movies_db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
$movies = array(
"comedy" => array("The Hangover","Knocked Up","Due Date"),
"drama" => array("The Shawshank Redemption","The Green Mile","Requiem for a Dream"),
"horror" => array("Halloween","The Conjuring","The Shining")
);
?>
26 changes: 26 additions & 0 deletions search_movie.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
include('movies_db.php');
session_start();


$_SESSION['results_array'] = search($_POST['category'], $_POST['moviename']);

header('Location: /php-intro-exercise/display.php');

function search($category, $string)
{
global $movies;
$results = array();
$movies_array = $movies[$category];
for($i=0; $i<count($movies_array); $i++)
{
if(stristr($movies_array[$i], $string) !== false)
{
array_push($results, $movies_array[$i]);
}
}
return $results;
}


?>
85 changes: 85 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@

form {
display: inline-block
text-align: center;
margin: 0 auto;
border: 1px solid #c6c7cc;
border-radius: 5px;
font: 14px/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
overflow: hidden;
width: 240px;
}
fieldset {
border: 0;
margin: 0;
padding: 0;
}
input {
border-radius: 5px;
font: 14px/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
margin: 0;
}
.search-info {
padding: 20px 20px 0 20px;
}
.search-info label {
color: #395870;
display: block;
font-weight: bold;
margin-bottom: 20px;
}
.search-info input {
background: #fff;
border: 1px solid #c6c7cc;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .1);
color: #636466;
padding: 6px;
margin-top: 6px;
width: 100%;
}
.search-action {
background: #f0f0f2;
border-top: 1px solid #c6c7cc;
padding: 20px;
}
.search-action .btn {
background: linear-gradient(#49708f, #293f50);
border: 0;
color: #fff;
cursor: pointer;
font-weight: bold;
float: left;
padding: 8px 16px;
}
.account-action label {
color: #7c7c80;
font-size: 12px;
float: left;
margin: 10px 0 0 20px;
}

#customers {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
width: 20%;
border-collapse: collapse;
}

#customers td, #customers th {
font-size: 1em;
border: 1px solid #98bf21;
padding: 3px 7px 2px 7px;
}

#customers th {
font-size: 1.1em;
text-align: center;
padding-top: 5px;
padding-bottom: 4px;
background-color: #A7C942;
color: #ffffff;
}

#customers tr.alt td {
color: #000000;
background-color: #EAF2D3;
}