jackie11 Posted January 23, 2007 Share Posted January 23, 2007 HiI have set up a search for my db, which searches the surname of people held on the db. It works ok, but the only problem I am having is that if there is more than one person woith the same surname it only displays one of them, how can I go about tellling it to display all results it has found My code is: [code]<html><head><title>Employee Index</title></head><body> <h1><img src="etc/Logo_pic_2.JPG"></h1><?php$search = $_POST["search"]; mysql_connect("localhost", "root", "") or die(mysql_error());mysql_select_db("employee_index") or die(mysql_error()); $query = "SELECT * FROM employee WHERE Surname = '$search'"; $result = mysql_query ($query)or die(mysql_error()); if (!mysql_num_rows($result)) {print "<p><BR><B>Sorry no results found - please try again!</BR> </p>" ;exit;}else{while ($row = mysql_fetch_array($result)) { extract($row); $Employee_ID = $row['Employee_ID']; $Surname = $row['Surname']; $Forename = $row['Forename']; $Job_title = $row['Job_title']; $Office_location = $row['Office_location']; $Telephone = $row['Telephone']; $Email = $row['Email']; $Expertise = $row['Expertise']; $Hobbies = $row['Hobbies']; $DOB = $row['DOB']; $Picture = "<a href='../test_2/pics/" . $row['Picture'] . "' border='0'><img src='../test_2/pics/" . $row['Picture'] . "' border='0' width='90' height='100'></a>"; }}echo "<table cellspacing='15'>"; echo "<tr><td colspan='20'><hr></td></tr>"; echo "<th>ID</th><th>Picture</th><th>Surname</th><th>Forename</th><th>Job Title</th> <th>Office Location</th><th>Telephone</th> <th>Email</th><th>Expertise</th><th>Hobbies</th><th>DOB</th>"; echo "<tr><td colspan='20'><hr></td></tr>"; echo " <td>$Employee_ID</td>\n <td>$Picture</td>\n <td>$Surname</td>\n <td>$Forename</td>\n <td>$Job_title</td>\n <td>$Office_location</td>\n <td>$Telephone</td>\n <td>$Email</td>\n <td>$Expertise</td>\n <td>$Hobbies</td>\n <td>$DOB</td>\n </tr>\n"; echo "<tr><td colspan='20'><hr></td></tr>\n"; echo "</table>\n"; ?><p style="text-align: left;"><a href="index.html"><img style="border: 0px solid ; width: 94px; height: 47px;" alt="Home" src="etc/Home_button.JPG"></a></p></span></span></body></html>[/code]ThanksJackie :-\ Link to comment https://forums.phpfreaks.com/topic/35362-displaying-multiple-search-results/ Share on other sites More sharing options...
ted_chou12 Posted January 23, 2007 Share Posted January 23, 2007 if i am not wrong:[code]<html><head><title>Employee Index</title></head><body> <h1><img src="etc/Logo_pic_2.JPG"></h1><?php$search = $_POST["search"]; mysql_connect("localhost", "root", "") or die(mysql_error());mysql_select_db("employee_index") or die(mysql_error()); $query = "SELECT * FROM employee WHERE Surname = '$search'"; $result = mysql_query ($query)or die(mysql_error()); if (!mysql_num_rows($result)) {print "<p><BR><B>Sorry no results found - please try again!</BR> </p>" ;exit;}else{while ($row = mysql_fetch_array($result)) { extract($row); $Employee_ID = $row['Employee_ID']; $Surname = $row['Surname']; $Forename = $row['Forename']; $Job_title = $row['Job_title']; $Office_location = $row['Office_location']; $Telephone = $row['Telephone']; $Email = $row['Email']; $Expertise = $row['Expertise']; $Hobbies = $row['Hobbies']; $DOB = $row['DOB']; $Picture = "<a href='../test_2/pics/" . $row['Picture'] . "' border='0'><img src='../test_2/pics/" . $row['Picture'] . "' border='0' width='90' height='100'></a>"; echo "<table cellspacing='15'>"; echo "<tr><td colspan='20'><hr></td></tr>"; echo "<th>ID</th><th>Picture</th><th>Surname</th><th>Forename</th><th>Job Title</th> <th>Office Location</th><th>Telephone</th> <th>Email</th><th>Expertise</th><th>Hobbies</th><th>DOB</th>"; echo "<tr><td colspan='20'><hr></td></tr>"; echo " <td>$Employee_ID</td>\n <td>$Picture</td>\n <td>$Surname</td>\n <td>$Forename</td>\n <td>$Job_title</td>\n <td>$Office_location</td>\n <td>$Telephone</td>\n <td>$Email</td>\n <td>$Expertise</td>\n <td>$Hobbies</td>\n <td>$DOB</td>\n </tr>\n"; }//I put} after the whole html code, therefore you can have a set of html per result. echo "<tr><td colspan='20'><hr></td></tr>\n"; echo "</table>\n";}//this is after everything, so you can be sure nothing shows up when no results.?><p style="text-align: left;"><a href="index.html"><img style="border: 0px solid ; width: 94px; height: 47px;" alt="Home" src="etc/Home_button.JPG"></a></p></span></span></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/35362-displaying-multiple-search-results/#findComment-167124 Share on other sites More sharing options...
jackie11 Posted January 23, 2007 Author Share Posted January 23, 2007 Hi Works a treat, cheers! :) :) :) :)Jackie Link to comment https://forums.phpfreaks.com/topic/35362-displaying-multiple-search-results/#findComment-167240 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.