stu1040 Posted January 9, 2012 Share Posted January 9, 2012 Hi All. What should I be looking for if I want to display all relevant data from a clicked link. There are 5 cities. So if I click ‘birmingham’ then everything about birmingham would display, london and so forth on one page called ‘locations.php’ The links work fine below and display one city when clicked, when I know there are 3 of each in the database. I was thinking in the lines of a ‘while loop’ or similar! Wrong direction? locations landing page $id = mysql_real_escape_string(trim($_GET['id'])); $data = mysql_query("SELECT location FROM cities WHERE id = '$id' ") or die(mysql_error()); $info = mysql_fetch_array( $data ); { Print "".$info['location'] .""; } I have 5 x city links from this, works fine. $data = mysql_query("SELECT id, location FROM cities GROUP BY location ORDER BY id ASC") OR DIE (mysql_error()); while($info = mysql_fetch_array($data)) { Print "<a href=locations.php?id=".$info['id']."'>".$info['location'] ."</a><br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/254669-displaying-relevant-data/ Share on other sites More sharing options...
blacknight Posted January 9, 2012 Share Posted January 9, 2012 yes a while loop would achieve what you want Quote Link to comment https://forums.phpfreaks.com/topic/254669-displaying-relevant-data/#findComment-1305855 Share on other sites More sharing options...
ManiacDan Posted January 9, 2012 Share Posted January 9, 2012 For the love of god space out your code. Why are your line breaks completely random? Your code, fixed: $id = mysql_real_escape_string(trim($_GET['id'])); $data = mysql_query("SELECT location FROM cities WHERE id = '$id' ") or die(mysql_error()); $info = mysql_fetch_array( $data ); { Print "".$info['location'] .""; } $data = mysql_query("SELECT id, location FROM cities GROUP BY location ORDER BY id ASC") OR DIE (mysql_error()); while($info = mysql_fetch_array($data)) { Print "<a href=locations.php?id=".$info['id']."'>".$info['location'] ."</a><br />"; } Now that it's formatted properly, you can see that your first block has a print() statement completely on its own inside an unnecessary set of curly braces. Why? There's no reason for it to be like that. You need a while loop there, which you might have thought you HAD already since you had the braces. Quote Link to comment https://forums.phpfreaks.com/topic/254669-displaying-relevant-data/#findComment-1305867 Share on other sites More sharing options...
stu1040 Posted January 9, 2012 Author Share Posted January 9, 2012 Thanks Blacknight, I'll try that. Quote Link to comment https://forums.phpfreaks.com/topic/254669-displaying-relevant-data/#findComment-1305870 Share on other sites More sharing options...
stu1040 Posted January 9, 2012 Author Share Posted January 9, 2012 ok, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/254669-displaying-relevant-data/#findComment-1305877 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.