Jump to content


Photo

Search function in relation to standard data display


  • Please log in to reply
1 reply to this topic

#1 programguru

programguru
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 03 July 2006 - 02:53 PM

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 function
function 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>";
}
THIS FORUM KEEPS PUTTING ME IN MY PLACE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#2 tfoster

tfoster
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 03 July 2006 - 04:23 PM

Is searchlast getting the correct value?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users