Jump to content

help in duplicate listing


snake310

Recommended Posts

i have a code:

$inter="SELECT model FROM $get2";
$id_rez=mysql_query($inter);
$row=mysql_num_rows($id_rez);
while($rand=mysql_fetch_row($id_rez))
for($i=0;$i<$row;$i++)
echo "<option>".$rand[$i]."</option>";
So this works fine , but i dont know how to evade to list every item just once , like if i have 3 of the same model i would like to show only 1

pls help i tried a lot of stuff it didnd`t work
Link to comment
https://forums.phpfreaks.com/topic/33586-help-in-duplicate-listing/
Share on other sites

Since what you fetch from mysql is an array anyways, try this:
<?php
// Assign values to array
$one = array(1,2,3,4,3,6,1,3,2);

// Create an array of unique values from $one
$two = array_unique($one);

// Output as proof
echo "<pre>\n";
print_r($two);
echo "</pre>\n";
?>
This is the best way to do what you're after...

[code]<?php
$inter = "SELECT DISTINCT model FROM $get2";
$id_rez = mysql_query($inter);
while ($rand = mysql_fetch_array($id_rez, MYSQL_ASSOC)){
  echo "<option>".$rand['model']."</option>";
}
?>[/code]

Regards
Huggie

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.