mforan Posted January 5, 2009 Share Posted January 5, 2009 heres my basic code Ive made: <select name="squadp" id="squadp"><option value=""></option> <?php $query = "SELECT sender FROM news WHERE receiver='$user' AND type='ATTACK' ORDER BY id DESC LIMIT 20"; $result = mysql_query($query) or die("Error: ".mysql_error()); $alli = array(); while ($row = mysql_fetch_array($result, MYSQL_NUM)) {$alli[] = $row[0];} $query = "SELECT receiver FROM news WHERE sender='$user' AND type='ATTACK' ORDER BY id DESC LIMIT 20"; $result = mysql_query($query) or die("Error: ".mysql_error()); $alli2 = array(); while ($row = mysql_fetch_array($result, MYSQL_NUM)) {$alli2[] = $row[0];} for ($i = 0; $i < count($alli); $i++) { if ($alli[$i] != "$user") { echo '<option value="',$alli[$i],'">',$alli[$i]; } } for ($i = 0; $i < count($alli2); $i++) { if ($alli2[$i] != "$user") { echo '<option value="',$alli2[$i],'">',$alli2[$i]; } } ?> </select> my problem is, i need only 1 sender selected. this is a bit hard to explain. basically the things the querys are selecting are not required. is there anyway to prevent a duplicate value of "sender" being selected. i want output to look like a b c d not a a a b b c d this make anysense to anyone? is this even possible to do? the LIMIT is because i only need to output 20 results. Link to comment https://forums.phpfreaks.com/topic/139600-solved-prevent-doubles/ Share on other sites More sharing options...
bluesoul Posted January 5, 2009 Share Posted January 5, 2009 SELECT DISTINCT sender, etc. Link to comment https://forums.phpfreaks.com/topic/139600-solved-prevent-doubles/#findComment-730330 Share on other sites More sharing options...
mforan Posted January 5, 2009 Author Share Posted January 5, 2009 SELECT DISTINCT sender, etc. oh crap. lmao, i overlooked this command! cheers man!! Link to comment https://forums.phpfreaks.com/topic/139600-solved-prevent-doubles/#findComment-730336 Share on other sites More sharing options...
redarrow Posted January 5, 2009 Share Posted January 5, 2009 Afther doing that try using a mysql join it better. Link to comment https://forums.phpfreaks.com/topic/139600-solved-prevent-doubles/#findComment-730337 Share on other sites More sharing options...
mforan Posted January 5, 2009 Author Share Posted January 5, 2009 Afther doing that try using a mysql join it better. sorry what do you mean mate? Link to comment https://forums.phpfreaks.com/topic/139600-solved-prevent-doubles/#findComment-730341 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.