Alura Posted July 15, 2010 Share Posted July 15, 2010 Hello - I'm new to PHP and I am working on a database to display information about various species of snakes, and eventually want to progress to information about each individual snake in our collection at my workplace. As I'm getting used to PHP, I've decided to concentrate on just simple species information before tackling the larger project. I set up the DB in MAMP and have created a simple PHP navigation page with a table linked to the DB that works fine for people browsing species, and it is set up to take them to a display page set up to show the specific species clicked from the table with this code on the "VIEW" link: <a href="species_display.php?Scientific=<?php echo $row_specieslist['Scientific_Name']; ?>">view</a> My table is called "specieslist", and my URL parameter is "Scientific", and the results page is "species_display.php". I set this up via Dreamweaver's toolboxes. Since we have over 35 species (and can go up to 300), I have been working on a search option for my site as well, and while it will return the desired results in a table, I am unsure as to how to add the above 'VIEW" Link to the tabled results. I've tried modifications of the above link code, but have been unsuccessful as yet in getting it to work. Am I even on the right track? Here is my search page, created after following some online tutorials and tweaked with advice from this forum: <HTML> <head> <title>Snakebook Search Engine</title> </head> <body> <form action='search.php' method='GET'> <p><img src="images/Snakebook-Logo.png" width="311" height="83" /> <input type='text' size='50' name='search' /> </p> <p> <input type='submit' name='submit' value='Search' /> </p> </center> </font> </form> </body> </HTML> [code=php:0] <?php //get data $button = $_GET['submit']; $search = $_GET['search']; if (!$button) echo "You didn't submit a keyword."; else { if (strlen($search)<=2) echo "Search not valid. Search term too short."; else { echo "You searched for <b>$search</b> <hr size='1'>"; //connect to our database mysql_connect("localhost:8889","root","root") or die ('Error connecting'); mysql_select_db("snakebook"); { //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if ($x==1) $construct .="Scientific_Name LIKE '%$search_each%' OR Common_Name LIKE '%$search_each%' OR Physical_Characteristics LIKE '%$search_each%' OR Geographic_Range LIKE '%$search_each%' OR Diet LIKE '%$search_each%' OR Venom LIKE '%$search_each%' OR Habitat LIKE '%$search_each%' OR Notes LIKE '%$search_each%' "; else $construct .=" OR Scientific_Name '%$search_each%' OR Common_Name LIKE '%$search_each%' OR Physical_Characteristics LIKE '%$search_each%' OR Geographic_Range LIKE '%$search_each%' OR Diet LIKE '%$search_each%' OR Venom LIKE '%$search_each%' OR Habitat LIKE '%$search_each%' OR Notes LIKE '%$search_each%' "; } //echo out construct $construct = "SELECT * FROM specieslist WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "No results found."; else { echo "<b>$foundnum</b> result(s) found.<p><hr size='1'>"; while ($runrows = mysql_fetch_assoc($run)) { //get data to display echo "<center><table border='0' cellpadding='5' cellspacing='0'> " ; $common = $runrows['Common_Name']; $scientific = $runrows['Scientific_Name']; $thumbnail = $runrows['Thumbnail']; //display data echo "<tr> <td><strong>$thumbnail</strong></td> <td><strong><i>$scientific</i></strong></td> <td><strong>$common</strong></td> <td><strong>$view</strong></td> </tr>" ; } } } } } ?> [/code] I apologize for any weird spacing or sloppy coding - I'm still learning the correct way to write all of this. Any help is appreciated, Thanks! Link to comment https://forums.phpfreaks.com/topic/207845-how-to-add-a-dynamic-link-generated-by-phpmysql-db-search-results/ Share on other sites More sharing options...
AMcHarg Posted July 16, 2010 Share Posted July 16, 2010 Try this: //display data echo "<tr> <td><strong>$thumbnail</strong></td> <td><strong><i>$scientific</i></strong></td> <td><strong>$common</strong></td> <td><a href='species_display.php?Scientific=$scientific'><strong>view</strong></a></td> </tr>" Link to comment https://forums.phpfreaks.com/topic/207845-how-to-add-a-dynamic-link-generated-by-phpmysql-db-search-results/#findComment-1086978 Share on other sites More sharing options...
Alura Posted July 16, 2010 Author Share Posted July 16, 2010 Thanks. That seemed to be the bit I needed to fix up. Unfortunately, my results display page is acting up now. Win one, lose one. At least it's Friday, and I'll probably figure it out over the weekend. Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/207845-how-to-add-a-dynamic-link-generated-by-phpmysql-db-search-results/#findComment-1087205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.