Extended Search Results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gavenp
Forum Newbie
Posts: 6
Joined: Sat Jun 09, 2007 3:03 am

Extended Search Results

Post by gavenp »

I have a search results page the returns information based on a simple search.

Code: Select all

<html>

<style type="text/css">
<!--
a:link {
	color: #0000FF;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #FF0000;
}
a:hover {
	text-decoration: none;
	color: #FF0000;
}
a:active {
	text-decoration: none;
	color: #FF0000;
}
-->
</style>

<body>
<? 
if ($search) // perform search only if a string was entered. 
{ 
mysql_connect('localhost','xxxxxx','xxxxxx') or die ("Problem connecting to DataBase"); 
$srch="%".$search."%"; 
$query = "select * from visitors WHERE Name LIKE '$srch' || Last LIKE '$srch' || email LIKE '$srch' || comment LIKE '$srch'"; 

$result = mysql_db_query("xxxxxx", $query); 

if ($result) 
{ 
echo "Here are the results:<br><br>"; 
echo "<table width=90% align=center border=1><tr> 
<td align=center bgcolor=#00FFFF>Visit time and date</td> 
<td align=center bgcolor=#00FFFF>User Name</td> 
<td align=center bgcolor=#00FFFF>Last Name</td> 
<td align=center bgcolor=#00FFFF>Email</td> 
</tr>"; 

while ($r = mysql_fetch_array($result)) { // Begin while 
$ts = $r["TimeStamp"]; 
$name = $r["Name"]; 
$last = $r["Last"]; 
$email = $r["email"]; 
$comment = $r["comment"]; 
echo "<tr> 
<td>$ts</td> 
<td><a href= $name>$name</td> 
<td>$last</td> 
<td><a href= mailto:$email>$email</td></tr> 
<tr> <td colspan=4 bgcolor=\"#ffffa0\">$comment</td> 
</tr>"; 
} // end while 
echo "</table>"; 
} else { echo "problems...."; } 
} else { 
echo "Search string is empty. <br> Go back and type a string to search"; 
} 
include ('links.x'); 
?> 
</body>
</html>
What I would like to do is to make the "name" become a hyperlink that you can click on and will take you to another page that shows the complete individual record laid out in a table. There are approximatly 17 additional colums of information that will need to be displayed on the next search page.
User avatar
waradmin
Forum Contributor
Posts: 240
Joined: Fri Nov 04, 2005 2:57 pm

Post by waradmin »

This isn't too complicated, have a link pass the name through the URL then have another page that reads it using $_GET and query again.

Code: Select all

while ($r = mysql_fetch_array($result)) { // Begin while
$ts = $r["TimeStamp"];
$name = $r["Name"];
$last = $r["Last"];
$email = $r["email"];
$comment = $r["comment"];
echo "<tr>
<td>$ts</td>
<td><a href=\"somepage.php?name=" . $name . "\">$name</a></td>
<td>$last</td>
<td><a href= mailto:$email>$email</td></tr>
<tr> <td colspan=4 bgcolor=\"#ffffa0\">$comment</td>
</tr>";
} // end while
echo "</table>";
} else { echo "problems...."; }
} else {
echo "Search string is empty. <br> Go back and type a string to search";
}
Then make a page called somepage.php...

Code: Select all

$name = $_GET['name']; // pulls the name=_____ from the URL

$result = mysql_query("SELECT *FROM visitors WHERE Name='$name'") or die(mysql_error());
$row = mysql_fetch_array($result);

// then echo your results here
Post Reply