Hey folks. Here’s what I’ve got:
I’ve created two pages. On the first page there is a a search box with a form button to execute the search of a movie database that I created. There are also alphabetical links for the user to click on if they want a list of all movies that start with “A” for example. (i.e. A | B | C | D). The second page is, of course, the results page that will display movies from the database based on the user’s search or letter selection.
Here’s the PHP code I’m using on the second page to grab the appropriate rows from the movies table:
<?php
$search = $_GET['search'];
$ID = $_GET['ID'];
//echo "$ID"
$linkID = mysql_connect("localhost", "root", "") or die('I cannot connect to the database.');
mysql_select_db("movies");
// Check if user did a search or selected a letter
if($_GET['ID'] == true){
$result1 = mysql_query("SELECT * FROM movies WHERE Title LIKE '$ID%'");
$row1 = mysql_fetch_assoc($result1);
}
elseif($_GET['search'] == true){
$result1 = mysql_query("SELECT * FROM movies WHERE Title LIKE '$search'");
$row1 = mysql_fetch_assoc($result1);
}
else {
echo "You entered no search criteria. Please try again.";
}
?>
<?php
while($row1 = mysql_fetch_assoc($result1)){
echo $row1['Title'];
echo "<br />";
}
?>
It does, in fact, work. However, it skips the first row that’s within the search parameters. So if they did a search for “T” and I have five movies that start with the letter “T” it will only display the last four.
Anyone know why?