rhock_95 Posted May 12, 2008 Share Posted May 12, 2008 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 Quote Link to comment Share on other sites More sharing options...
FVxSF Posted May 12, 2008 Share Posted May 12, 2008 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? Quote Link to comment Share on other sites More sharing options...
rhock_95 Posted May 12, 2008 Author Share Posted May 12, 2008 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... Quote Link to comment Share on other sites More sharing options...
rhock_95 Posted May 13, 2008 Author Share Posted May 13, 2008 I'm still looking for suggestions on a way this can be done TIA Quote Link to comment Share on other sites More sharing options...
947740 Posted May 13, 2008 Share Posted May 13, 2008 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. Quote Link to comment Share on other sites More sharing options...
rhock_95 Posted May 13, 2008 Author Share Posted May 13, 2008 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... Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 13, 2008 Share Posted May 13, 2008 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. Quote Link to comment Share on other sites More sharing options...
rhock_95 Posted May 14, 2008 Author Share Posted May 14, 2008 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? Quote Link to comment Share on other sites More sharing options...
947740 Posted May 14, 2008 Share Posted May 14, 2008 If city=Orlando, or something like that, is not in the URL, you will not be able to use the $_GET function. Quote Link to comment Share on other sites More sharing options...
rhock_95 Posted May 14, 2008 Author Share Posted May 14, 2008 so it's not possible? Quote Link to comment Share on other sites More sharing options...
947740 Posted May 14, 2008 Share Posted May 14, 2008 You cannot use $_GET['city'] if there is not a city value in the URL, that is all I was saying. It is possible to do what you want, however. Quote Link to comment Share on other sites More sharing options...
rhock_95 Posted May 14, 2008 Author Share Posted May 14, 2008 care to offer a clue? I am not a php coder...I'm just trying to make an existing application a litter better thanks Quote Link to comment Share on other sites More sharing options...
rhock_95 Posted May 15, 2008 Author Share Posted May 15, 2008 I am still looking for someone capable of helping me with this project...everyone seems to agree that it's possible but nobody has been able to help so far... anyone? TIA Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted May 15, 2008 Share Posted May 15, 2008 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 Quote Link to comment Share on other sites More sharing options...
rhock_95 Posted May 15, 2008 Author Share Posted May 15, 2008 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 ? Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted May 15, 2008 Share Posted May 15, 2008 soz it should be if(isset($_GET['city'])) Quote Link to comment Share on other sites More sharing options...
rhock_95 Posted May 15, 2008 Author Share Posted May 15, 2008 now the error jumps to this line...(I tried what I could) city = $_GET(city); Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted May 15, 2008 Share Posted May 15, 2008 i thought you might of worked out that they needed to be changed like the one before, as i said the code is to help , it is not tested. This should be changed city = $_GET['city']; Quote Link to comment Share on other sites More sharing options...
947740 Posted May 15, 2008 Share Posted May 15, 2008 Should it not be $city = $_GET['city']; ? Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted May 15, 2008 Share Posted May 15, 2008 yer, soz, i just copied and pasted , must of cut that bit out Quote Link to comment Share on other sites More sharing options...
rhock_95 Posted May 15, 2008 Author Share Posted May 15, 2008 I just saw that still working on it Quote Link to comment Share on other sites More sharing options...
947740 Posted May 15, 2008 Share Posted May 15, 2008 I was just making sure. Quote Link to comment Share on other sites More sharing options...
rhock_95 Posted May 15, 2008 Author Share Posted May 15, 2008 Ok so far so good but no link (city) displays... I get a parse error here is the original "city" display echo ' <td>'.$row['city'].'</td>'; Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted May 15, 2008 Share Posted May 15, 2008 can you explain some more? Quote Link to comment Share on other sites More sharing options...
947740 Posted May 15, 2008 Share Posted May 15, 2008 rhock_95-was the code you just posted supposed to be a hyperlink? If so, you need the <a> tags. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.