Displaying multiple content

I am really a newbie with PHP and I’m trying to reverse engineer some code.

A user submits a search request, let’s say a user tries to search for any products with the word “water”. A page comes up with a list of products that has the word water in it. When the user clicks on one of the products, it takes them to a list of “companies” that offer the product.

So far, this is achievable and currently works.

But, I need to now add a new element to all of this. When the page of companies is displayed, I need to have a banner ad at the top of the page.

The banner ad all depends on what the user tried searching for. So in essence, I need the PHP code to call up the banner ad that is associated with whatever product the user searched for.

My Table is called “Categories” and within that Table, I have three columns called “Cat_id” “Category_Name” and “url”. The “url” is the new column I created for the url of where the banner ad image is going to be.

My PHP Code for the page of Companies that appears is:

[php]<?php

include(“connect.php”);

//Get the search variable from URL

$var=@$_GET[‘search_txt’]; //search text that the visitor has searched for

$trimmed = trim($var); //trims whitespace

//rows to return

$limit=10;

//check for an empty string and display a message.

if($trimmed == “”)

{

echo “<div class=“warning”>Your search returned zero results.  Please enter something to search for.”;

exit;

}

//check for a search parameter

if(!isset($var))

{

echo “<div class=“warning”>We dont seem to have a search parameter!”;

exit;

}

//build sql query

$query="SELECT Distinct l.name1, l.name2, l.address1, l.address2, l.city, l.state, l.zip, l.phone1, l.phone2, l.fax, l.Email, l.Website_url, l.Listing_id, l.idl

    FROM Listings l, Categories c, CategoryListings cl 

    WHERE c.Category_Name like \"$trimmed%\" AND c.Cat_ID=cl.Cat_id AND l.idl=cl.idl 

    ORDER BY l.name1 asc";

$result=mysql_query($query);

$numrows=mysql_num_rows($result);

//if no results

if($numrows ==0)

{

echo “

Results
”;

echo “

Sorry, your search for “” . $trimmed . “” in the Products and Services category returned zero results.

Please check your entry and try your search again.
”;

} else {

//display what the person searched for

echo “

You searched for Companies dealing in:  
“” .$var. “”
”;

//begin to show results set

//now you can display the results returned

while ($row = mysql_fetch_array($result))

{

echo "<div class='businessresults'>";

echo "<div class='name1'><strong>{$row['name1']}</strong></div>" . '<br />';

echo "<div class='name2'><strong>{$row['name2']}</strong></div>" . '<br />';

echo "<div class='businessresults1'><div class='address'>{$row['address1']}" . "  " . "{$row['address2']}" . '&nbsp;|&nbsp;';

echo "{$row['city']}" . ",&nbsp;" . "{$row['state']}" . " &nbsp;" . "{$row['zip']}&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"http://maps.google.com/maps?q={$row['address1']},+{$row['city']},+{$row['state']},+{$row['zip']}\" target='_blank'>Map</a>" . '<br /><br />';

echo "<strong>Email:</strong> &nbsp;<a href=\"mailto:{$row['Email']}\">{$row['Email']}</a>" . '<br />';

echo "<strong>Website:</strong> &nbsp;<a href=\"http://{$row['Website_url']}\" target='_blank'>{$row['Website_url']}</a></div></div>" . '<br />';

echo "<div class='phone1'>{$row['phone1']}</div>" . '<br />';

echo "<div class='phone2'><strong>Phone2:</strong> {$row['phone2']}" . '<br />';

echo "<strong>Fax:</strong> {$row['fax']}</div>". '<br />';

echo "<br /><div class='address'>To view Products and Services from this Company..." . "<a href=\"services.php?id={$row['idl']}&?height=220&width=400\" class=\"thickbox\" title=\"Products and Services\">Click Here</a></div>";

echo "</div>";

}

}

?>[/php]

Any help or direction here would be appreciated. Again, I need to figure out what PHP code I need to have in order for the page to know what banner ad to call from the “Categories” Table in the Column called “url”.

Sponsor our Newsletter | Privacy Policy | Terms of Service