Jump to content

[SOLVED] prevent doubles


mforan

Recommended Posts

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

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.