Page 1 of 1

MySQL doubling Array contents

Posted: Tue Mar 23, 2010 5:18 pm
by andrew_hodgson
When I query my db it seems be be returning an array with double the entries that it should have, like this,

Code: Select all

Array ( [0] => 1 [title_id] => 1 [1] => Fifa 10 [game_title] => Fifa 10 [2] => COD 4 [wanted1] => COD 4 )
The [0] [1] and [2] are just doubles of the entries that I've made.

query looks like this,

Code: Select all

<?php 
$sql = "SELECT * " ;
$sql .= "FROM current_offers ";
$sql .= "WHERE game_title='{$_GET['title']}' AND wanted1='{$_GET[wanted1]}'";
 
$result = query($sql);
 
while ($row = mysql_fetch_array($result)) {
    print_r($row);
    echo "<br />";
}
 
?>
db structure looks like this,

Code: Select all

    
   title_id    game_title  wanted1 
            1    Fifa 10       COD 4            
            2    FIFA           NULL   

Re: MySQL doubling Array contents

Posted: Tue Mar 23, 2010 8:06 pm
by Eran
Please read the manual on mysql_fetch_array(), and see what is the default fetching mode
http://php.net/manual/en/function.mysql-fetch-array.php