snake310 Posted January 10, 2007 Share Posted January 10, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/33586-help-in-duplicate-listing/ Share on other sites More sharing options...
mkosmosports Posted January 10, 2007 Share Posted January 10, 2007 So are you trying to list the "model" item only once (no duplicates)?I assume you are so change the $inter variable to read:$inter="SELECT DISTINCT model FROM $get2"; Quote Link to comment https://forums.phpfreaks.com/topic/33586-help-in-duplicate-listing/#findComment-157320 Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 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 proofecho "<pre>\n";print_r($two);echo "</pre>\n";?> Quote Link to comment https://forums.phpfreaks.com/topic/33586-help-in-duplicate-listing/#findComment-157322 Share on other sites More sharing options...
snake310 Posted January 10, 2007 Author Share Posted January 10, 2007 thx that is what i needed but there is still one thing it leaves blank fields... any ide what to do? Quote Link to comment https://forums.phpfreaks.com/topic/33586-help-in-duplicate-listing/#findComment-157323 Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 blank fields? ???, sorry, i dont understand... Quote Link to comment https://forums.phpfreaks.com/topic/33586-help-in-duplicate-listing/#findComment-157325 Share on other sites More sharing options...
snake310 Posted January 10, 2007 Author Share Posted January 10, 2007 what i am listing there is a select list menu and now it goes likemodel1(blank)(blank)model2(blank)model3and blank meant that it`s nothing there but it is selectible Quote Link to comment https://forums.phpfreaks.com/topic/33586-help-in-duplicate-listing/#findComment-157328 Share on other sites More sharing options...
snake310 Posted January 10, 2007 Author Share Posted January 10, 2007 btw Problem solved thx for the help guys Quote Link to comment https://forums.phpfreaks.com/topic/33586-help-in-duplicate-listing/#findComment-157329 Share on other sites More sharing options...
HuggieBear Posted January 10, 2007 Share Posted January 10, 2007 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]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33586-help-in-duplicate-listing/#findComment-157340 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.