Jump to content

Distinct data not displaying from links.


stu1040

Recommended Posts

The first segment of code below displays 5 x DISTINCT cities that are ‘a href’ linked, when clicked will land on a page called locations.php. My problem is, no data displays on the locations page. I could create 5 x different pages, but what’s the point when the whole page format is the same.

 

I’ve tried single quotes, and moving things about but I think it’s something to do with the landing page ‘id’.

 

Any guidance, ideas appreciated. Thanks.

 

LINKS PAGE

$data = mysql_query("SELECT DISTINCT location  FROM cities ") 
OR DIE (mysql_error()); while($info = mysql_fetch_array($data)) {  
Print '<p><a href=locations.php?id="'.$info['".$id."'].'">'.$info['location'] .'</a></p>';  } 

 

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

Link to comment
Share on other sites

Thanks for your input.

I’m not even sure what I should be googling, searching for to solve this problem.

 

If I remove the ‘id’ from the SELECT DISTINCT then I  get one of each city, but no data on the landing page.

If I add ‘id’ to the SELECT DISTINCT then I get duplicate cities and data shows on landing page.

 

Anyone know which direction I should be going, or what I should be studying?

 

Thanks in advance. 

 

$data = mysql_query("SELECT DISTINCT id,location FROM cities  ") 
OR DIE (mysql_error());  while($info = mysql_fetch_array($data)) {  
Print "<a href=locations.php?id=".$info['id']."'>".$info['location'] ."</a>"; }

 

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

Link to comment
Share on other sites

Thanks for everyones input.

It works.

Stu.

 

$data = mysql_query("SELECT DISTINCT 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 />"; }  

 

 
$id = mysql_real_escape_string(trim($_GET['id']));  
$data = mysql_query("SELECT id, location FROM cities  WHERE id = '$id'  GROUP BY location ORDER BY id ASC")  
or die(mysql_error()); $info = mysql_fetch_array( $data ); { 
Print "".$info['location'] .""; } 

Link to comment
Share on other sites

Thanks. I removed distinct after playing around with it.

What should I look for if I want to display everything to do with the link i’ve clicked. Such as clicked ‘london’ and everything related to london appeared, or ‘birmingham’ for example.

 

So far the city appears once, but I require everything to do with that city to appear on the landing page, such as click birmingham and 3 x hotels appear in birmingham or london for example.

 

Am I looking for a ‘while loop’ or similar?

 

$id = mysql_real_escape_string(trim($_GET['id']));  
$data = mysql_query("SELECT location, name FROM cities  WHERE id = '$id' ")  
or die(mysql_error()); $info = mysql_fetch_array( $data ); { 
Print "".$info['location'] ."    "; }

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.