mysql - php foreach is outputting everything twice -


everything works fine, output being listed twice.

so echos out: 'output a' 'output a' 'output b' 'output b' 'output c' 'output c' , on.

when mysql query in phpmyadmin, listed once. ideas?

what code doing going , getting many-to-many field

<?      $something = mysql_query('select userid users username ="'. $username .'"');     while ($row = mysql_fetch_array($something)) {         $barf = $row['userid'];     }     $result = mysql_query('select name items p left join list on p.item_id = up.item_id up.userid =  "' . $barf . '"');     while ($r = mysql_fetch_array($result)) {         foreach($r $uue) {             echo $uue . '<br>';}         }     } ?> 

try code:

while ($r = mysql_fetch_assoc($result)){   foreach($r $uue) {     echo $uue . '<br>';   } } 

you duplicate results because default (mysql_both flag) mysql_fetch_array returns 2x sized array : number-indexed + string-indexed.

so, example $r[0] , $r['name'] different elements in array contain same values.

also, should stop using mysql_* deprecated. read on mysqli_* functions.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -