Jump to content

hyperlink part of results display


rhock_95

Recommended Posts

hi,

I have a script that displayes search results as a list of vendors for particular products

 

the results include NAME;ADDRESS,CITY;TELEPHONE etc...

 

What I would like to do is "hyperlink" the "CITY" dispayed so when clicked it refines the results to disply only those vendors located in said CITY...

 

can I do this wihtin the script or does it have to be done in the stored (CITY) data in the database?

 

in the current script that searches for the products "$query" can I add a second variable $city and use a secondary GET script that will do what I want?

 

I am not a coder but I can hack scripts fairly well...if anyone has any code that does anything similar to this I would love to see it...TIA

Link to comment
Share on other sites

I'm not sure how much you know about databases but what I'd do is, once the City is clicked a query performed. Some thing along the lines of

 

SELECT * FROM table WHER City = $City

 

Of course, this all depends how the database is set up.

 

Do you have any code to share?

Link to comment
Share on other sites

Thanks for the reply...

 

as it stands now...the user has already selected a product category ($query) from a drop down menu...and the results are displayed...I then offer a second drop down menu ($city) where the user can refine the search to only show contacts located in the selected city...

 

I could make it easier (no drop down) for the user if the city names were hyperlinked that when clicked would display the "refined" results with the second variable ($city)...but I wanted the original script to do this not with the way the "city" name is entered into the db...I can do that but the the script that the "hyperlink" calls does not know what the original "$query" was...

 

$results = mysql_query("SELECT  `name` , `address` , `city` , `phone` , `www` ,`id` FROM `category_list` WHERE 1 AND `category` LIKE '%$query%'  ORDER BY name ASC LIMIT $page, $limit");
while ($data = mysql_fetch_array($results))

 

 

can you show me how to add the second variable ($city) to this query?

 

Thanks again...

 

 

Link to comment
Share on other sites

You could do something like this:

<?php
while($row = mysqli_fetch_array($results)) {

echo "<a href='file.php?city=$city'>$city</a>";
}
?>

 

You would then have a 'file.php' that would use a $_GET function to get the $city value, and then perform a query.  Hopefully I understood your question and my idea helps.

Link to comment
Share on other sites

Thanks for the reply and the effort...I see how this could be used but I don't see how it can help use in my existing script...

 

in a nutshell...all I want to do is hyperlink the city names in the displayed results (the product has already been selected...by clicking the city name it refines the query to just those vendors in the "clicked" city...

 

Thanks again...

Link to comment
Share on other sites

i believe that's what 947740 tried to show you. build a link as posted, passing the name of the city in the url and using the name of the city as the text in the link. the page file.php will use $_GET['city'] to get the value passed and can then query the database with that city name.

Link to comment
Share on other sites

i believe that's what 947740 tried to show you. build a link as posted, passing the name of the city in the url and using the name of the city as the text in the link. the page file.php will use $_GET['city'] to get the value passed and can then query the database with that city name.

 

how does "file.php" know what the original variable was ($query=product vendor) if it not passed in the URL? 

 

Link to comment
Share on other sites

if you want someone to code it for you , you are better trying the freelance section, if not listen to people's advice.

you would have something like this

<?php
if(isset($_GET(city))
{
city = $_GET(city);
//this is the changed query
}
else
{
//here is where the original query goes
}
?>
and this is the link that would be used 
<a href="?city=<?php echo $city; ?>"><?php echo $city; ?></a>

 

this should help you

Link to comment
Share on other sites

Thanks for the reply...I thought this was more what I was looking for...however...regardless of where I use this...I get parse errors on or about the first line:

 

 

if(isset($_GET(city))

 

I see an unclosed parentheses ?

 

 

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.