programguru Posted July 3, 2006 Share Posted July 3, 2006 I am writing a basic script:#1 below is a simple MySQL record extractor ===============================================#2 below is a search function that I would like to integrate w/ $query="SELECT * FROM contacts WHERE last='$searchlast'";$result=mysql_query($query); I want the search box on the same page as the results. I thought using an if statement would do the trick, but I cannot get it to work properly. Any suggestions?************************************************// #1 function db_form_output_html() { $user="######"; $password="######"; $database="######"; mysql_connect(localhost,$user,$password); @mysql_select_db($database) or die( "Unable to select database"); //this is what changes for the search function. $query="SELECT * FROM contacts "; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close();?><table align="center" border="1" cellspacing="2" cellpadding="2"><tr><th><font face="Arial, Helvetica, sans-serif">Name</font></th><th><font face="Arial, Helvetica, sans-serif">Phone</font></th><th><font face="Arial, Helvetica, sans-serif">Mobile</font></th><th><font face="Arial, Helvetica, sans-serif">Fax</font></th><th><font face="Arial, Helvetica, sans-serif">E-mail</font></th><th><font face="Arial, Helvetica, sans-serif">Website</font></th></tr><?$i=0;while ($i < $num) {$first=mysql_result($result,$i,"first");$last=mysql_result($result,$i,"last");$phone=mysql_result($result,$i,"phone");$mobile=mysql_result($result,$i,"mobile");$fax=mysql_result($result,$i,"fax");$email=mysql_result($result,$i,"email");$web=mysql_result($result,$i,"web");?><tr><td><font face="Arial, Helvetica, sans-serif"><? echo $first." ".$last; ?></font></td><td><font face="Arial, Helvetica, sans-serif"><? echo $phone; ?></font></td><td><font face="Arial, Helvetica, sans-serif"><? echo $mobile; ?></font></td><td><font face="Arial, Helvetica, sans-serif"><? echo $fax; ?></font></td><td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo $email; ?>">E-mail</a></font></td><td><font face="Arial, Helvetica, sans-serif"><a href="<? echo $web; ?>">Website</a></font></td></tr><?$i++;echo "</table>"; }}********************************************************// #2 contact manager search functionfunction cm_search() { echo "<center><form action=\"$PHP_SELF\" method=\"post\"> Last Name: <input type=\"text\" name=\"searchlast\"><br> <input type=\"submit\" value=\"Search\"> </form></center>";} Link to comment https://forums.phpfreaks.com/topic/13551-search-function-in-relation-to-standard-data-display/ Share on other sites More sharing options...
tfoster Posted July 3, 2006 Share Posted July 3, 2006 Is searchlast getting the correct value? Link to comment https://forums.phpfreaks.com/topic/13551-search-function-in-relation-to-standard-data-display/#findComment-52503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.