how to make mysql display one of each value
Moderator: General Moderators
how to make mysql display one of each value
If an array has duplicate values (a, a, b, b, b, c, d, d) is there any way to make it only have one of each? (a, b, c, d). Thanks!
okay distinct sort of worked... I have 3 entries to test it, and 2 are the same. I put it all in and I only get 2 results (it's working!) but they say: Resource id #4... Anyone ever heard of this before? Here's my code:
Thanks for the help!
Code: Select all
$title_xbox = mysql_query("select distinct title from review where subsystem='xbox'");
$num_xbox=mysql_numrows($title_xbox);
echo "<h4>Xbox:</h4>";
while($r=mysql_fetch_array($title_xbox))
{
echo "<a href=\"reviews.php?cmd=view&title=$title_xbox\">$title_xbox</a><br>";
}
if ($num_xbox == 0) {
echo "No Xbox Reviews Found<br><br>";
}- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
echo "<a href=\"reviews.php?cmd=view&title={$r['title']}\">{$r['title']}</a><br>";okay 1 more thing added on to that. Is there any way to get other values from the rows when using distinct? Or is there some way to do a second query to get the other values? here's the code I have so far:
What I would like is to be able to get the value 'subsystem' from the table. Thanks so much!
Code: Select all
$exact_results = mysql_query("select distinct title from review where title='$title' and subsystem='$subsystem'");
while($r=mysql_fetch_array($exact_results))
{
$e_title = $r["title"];
$e_subsystem = $r["subsystem"];
echo "<tr><td><a href=\"index.php?id=submit&cmd=form&title=$e_title&subsystem=$e_subsystem\">$e_title</a></td><td>$e_subsystem</td></tr>";
}- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
select distinct title, subsystem from review where subsystem='xbox'