php search results
I've seen alot of tutorials on search with php and mysql, but im having trouble with generating a link with the search result. For example say i have an item called "item1" in my db and the user searhes for item , item1 should be returned as a link so the us开发者_Go百科er can click the link to get more information about that product. Does anyone have any scripts , or snippets of code for how to acheive this?Thanks
You probably need to create an item page say item.php that accepts an id which will then search teh database for that item and display the item information.
Your search results will then have to display the name of the item in a link that also includes the id of the item.
<a href="item.php?id=<?php echo $itemid"?>"> <?php echo $itemname"?> </a>
This would of course be in a loop that goes through the list of items one at a time.
When the user clicks the link it will take them to item.php and send id as a parameter.
that's a simply example with no check and no control by datatype or query results. just start from it and do what you need...
<?php
//your db connection
//col1 is where the id is saved
//col2 is the url
$qry="SELECT col1, col2 FROM table WHERE col1='".$_GET['var']."'";
$result=mysql_fetch_array(mysql_query($sql));
echo '<a href="'.$result['col2'].'">LINK</a>';
?>
edit:
if you want a direct redirect do this instead of echoing
header('Location: '.$result['col2']);
精彩评论