Hi I have been on before and have found some great help on a php script to submit reviews to my site. I now have this working using PHP and my mysql database I set up and can fill in a form and submit to the fields of the table I created.
I also created a script to retrieve the table and display on my website all entries.
What I need now is some help with a search function. I found a good tutorial and have completed the search part and it sends back results to my page as hyperlinks that end in .php?id=1 etc... the number going up relating to the ID field of my mysql table. If I click on these hyperlinks I thought it would display the table entry for that ID but it just goes back to my search box.
To see what I mean if you go to http://www.guitarandsong.com/search_reviews.php and type in guitar it returns two results. That you can hover over and see the .php?id=1 end.
Any Ideas? Here is the code I have used so far from tutorials.
PHP Code:
<?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){ $name=$_POST['name']; $db=mysql_connect ("localhost", "web117-reviews", "weejon95") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db("web117-reviews"); $sql="SELECT ID, Title, Equipment FROM reviews WHERE Title LIKE '%" . $name . "%' OR Equipment LIKE '%" . $name ."%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Title =$row['Title']; $Equipment=$row['Equipment']; $ID=$row['ID']; echo "<ul>\n"; echo "<li>" . "<a href=\"search_reviews.php?id=$ID\">" .$Title . " " . $Equipment . " " . $Build . " " . $Functions . "</a></li>\n"; echo "</ul>"; } } else{ echo "<p>Please enter a search query</p>"; } } } if(isset($_GET['by'])){ $letter=$_GET['by']; $db=mysql_connect ("localhost", "web117-reviews", "weejon95") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db("web117-reviews");
$sql="SELECT ID, Title, Equipment FROM reviews WHERE Title LIKE '%" . $letter . "%' OR Equipment LIKE '%" . $letter ."%'";
$result=mysql_query($sql);
$numrows=mysql_num_rows($result); echo "<p>" .$numrows . " results found for " . $letter . "</p>";
while($row=mysql_fetch_array($result)){ $Title =$row['Title']; $Equipment=$row['Equipment']; $ID=$row['ID'];
echo "<ul>\n"; echo "<li>" . "<a href=\"search_reviews.php?id=$ID\">" .$Title . " " . $Equipment . "</a></li>\n"; echo "</ul>"; } } ?>
Last edited by chrishirst; 02-03-2010 at 08:11 PM..
Reason: php code tags added
|