Jump to content

Displaying multiple content


grovejeep

Recommended Posts

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

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.</div>";

exit;

}



//check for a search parameter

if(!isset($var))

{

echo "<div class=\"warning\">We dont seem to have a search parameter!</div>";

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 "<div class='noresults'>Results</div>";

echo "<div class='resultstext'>Sorry, your search for <i>"" . $trimmed . ""</i> in the Products and Services category returned zero results.<br /><br />Please check your entry and try your search again.</div>";

} else {



//display what the person searched for

echo "<div class='searchedfor'>You searched for Companies dealing in:  </div> <div class='searchedforvar'>"" .$var. ""</div>";



//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']}" . ' | ';

	echo "{$row['city']}" . ", " . "{$row['state']}" . "  " . "{$row['zip']}  |  <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>  <a href=\"mailto:{$row['Email']}\">{$row['Email']}</a>" . '<br />';

	echo "<strong>Website:</strong>  <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>";

	}

	

}

?>

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".

Link to comment
Share on other sites

Can't see anything in your code, so here's my English language version:

 

User selected a company. Your ads are associated with categories. You need to have some value that connects a company to a category and perform a query to locate the category record you want and then pull the url from the query and display it in an <img> tag on your output.

 

Make sense?

Link to comment
Share on other sites

First, think if a re-code (this is VERY poor code and has left you open to serious problems)

 

Second

 

To achieve what you want, we need more information.

 

My understanding, if I search for "Water" you will show me a banner related to water

 

Does this mean you will have banners for EVERY word in the dictionary?

 

How will these banners be generated?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.