MySQL doubling Array contents

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
andrew_hodgson
Forum Newbie
Posts: 9
Joined: Fri Mar 12, 2010 9:09 am

MySQL doubling Array contents

Post 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   
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: MySQL doubling Array contents

Post 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
Post Reply