Forum Moderators: coopster

Message Too Old, No Replies

Turn searched results into links, Using mysql and simple php

php search for a newbie

         

bbish007

6:46 pm on Aug 30, 2005 (gmt 0)

10+ Year Member



Ok I might be as new a newbie as they get, so please take it easy

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?

ChadSEO

7:30 pm on Aug 30, 2005 (gmt 0)

10+ Year Member



bbish007,

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

bbish007

4:34 pm on Sep 4, 2005 (gmt 0)

10+ Year Member



Thanks ChadSEO - its really helped