Forum Moderators: coopster
Using mysql and php, I have managed to patch together a simple search facility
using php to access my database of products. Upon clicking search it
returns each result a line at a time.
What I need to be able to do is turn these results into links that would go to secific product pages chosen. Also formatting the results that come from the search I would
like to be able to decide where for example the manufacturer, a
description, and a price should be listed on the page.
<p>Here is the results from your search....</p>
<?php
// Request the text of all the titles / names
$result = @mysql_query("SELECT * FROM Products WHERE name Like \"%$trimmed%\"
OR platform Like \"%$trimmed%\" ORDER BY name");
if (!$result) {
echo("<p>Error performing query: " . mysql_error() .
"</p>");
exit();
}
// Display the text of each titles / names in a paragraph
while ( $row = mysql_fetch_array($result) ) {
echo("<p>" . $row["name"] . $row["price"] .
"</p>");
}
?>
Thanks for any help you might be able to give?
Welcome to WebmasterWorld!
The line that you will want to modify is this one:
echo("<p>" . $row["name"] . $row["price"] . "</p>");
Now how you modify it will largely depend on your site and database structure. How are product URLs formatted? How are manufacturer/description stred in the database. One example might be:
echo("<p><a href=\"/products.php?id=" . $row["id"] . "\">" . $row["name"] . " Price:" . $row["price"] . "</a></p>");
There is no simple answer to this, so you'll probably have to do a lot of testing. Figure out in your head or on paper how you want it to look, then try to reproduce that. Good luck, and hope this helps a little bit.
Chad