jandrews Posted March 22, 2009 Share Posted March 22, 2009 Hello all, I am quite new to php and I can't seem to figure this one out although i have a feeling the answer is blindingly obvious. Once a query has been made to a database and the results displayed in a table, how would I hyperlink each result to display a different url variable when clicked on? I am sure that the $_Get comes into it somewhere but I'm not sure how to implement this code properly. Any help would be greatly appreciated James Quote Link to comment https://forums.phpfreaks.com/topic/150522-solved-hyperlinking-mysql-results/ Share on other sites More sharing options...
Maq Posted March 22, 2009 Share Posted March 22, 2009 Can we see your code? You would surround your query results in your while loop with href tags. Something similar to: Quote Link to comment https://forums.phpfreaks.com/topic/150522-solved-hyperlinking-mysql-results/#findComment-790627 Share on other sites More sharing options...
jandrews Posted March 22, 2009 Author Share Posted March 22, 2009 Brilliant! Thank You. But I don't want the hyperlinks to take the user to a different page, I just want the links to appear as variables in the url so that it will trigger other queries with url variables set. Do you know how to do this? Quote Link to comment https://forums.phpfreaks.com/topic/150522-solved-hyperlinking-mysql-results/#findComment-791130 Share on other sites More sharing options...
Maq Posted March 22, 2009 Share Posted March 22, 2009 Brilliant! Thank You. But I don't want the hyperlinks to take the user to a different page, I just want the links to appear as variables in the url so that it will trigger other queries with url variables set. Do you know how to do this? Not sure what you mean by this, something similar to? LINK Then on the processing page to get that variable you would do something like: $var1 = $_GET['var1']; Quote Link to comment https://forums.phpfreaks.com/topic/150522-solved-hyperlinking-mysql-results/#findComment-791132 Share on other sites More sharing options...
jandrews Posted March 22, 2009 Author Share Posted March 22, 2009 Yeah exactly, except the php code in the link doesn't seem to working. In other words, I am getting... "http://localhost:8888/bands.php?band=" instead of "http://localhost:8888/bands.php?band=example" in my url. Quote Link to comment https://forums.phpfreaks.com/topic/150522-solved-hyperlinking-mysql-results/#findComment-791152 Share on other sites More sharing options...
Maq Posted March 22, 2009 Share Posted March 22, 2009 Ok, then you're not getting any results from your database. Can I see the relevant code? Quote Link to comment https://forums.phpfreaks.com/topic/150522-solved-hyperlinking-mysql-results/#findComment-791154 Share on other sites More sharing options...
jandrews Posted March 22, 2009 Author Share Posted March 22, 2009 OK, I'll try to make as much sense as i can... I have a query which returns the names of various music bands in alphabetical order and it works. With you're help, I have managed to create a link for each result: <a href=<?php echo $row_artists['playlist_music']; ?>"><?php echo $row_artists['playlist_music']; ?></a> This is great because before I couldn't figure out how to do this. Now this gives me the same results hyperlinked with no problem. What I need to know now is how I use these same links but stay on the same page and just have the results link to a url variable of the same name when clicked on. For example, one of the results is Bryan Adams, so when I click on Bryan Adams, I want to see ?artist=Bryan Adams in my url Quote Link to comment https://forums.phpfreaks.com/topic/150522-solved-hyperlinking-mysql-results/#findComment-791176 Share on other sites More sharing options...
jandrews Posted March 22, 2009 Author Share Posted March 22, 2009 You are a legend. Thanks for you're help Just as you said: <tr> <td> <a href="bands.php?=<?php echo $row_artists['playlist_music']; ?>"><?php echo $row_artists['playlist_music']; ?></a></td> </tr> <?php } while ($row_artists = mysql_fetch_assoc($artists)); ?> </table></td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/150522-solved-hyperlinking-mysql-results/#findComment-791185 Share on other sites More sharing options...
Maq Posted March 22, 2009 Share Posted March 22, 2009 I think you're making this harder than it is. Let me give you an example. "testing.php" is the page you want to go to. $row_artists['playlist_music']="brian adams"; echo $_GET['music']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/150522-solved-hyperlinking-mysql-results/#findComment-791192 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.