Jump to content

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