php - php_mysql_assoc ignores first record -
hi there i'm trying query database records share same "itemid" table transaction list of operations done on items in database.
i've checked sql query in phpmyadmin , works correctly when run php code ignores first record every time. here's code
<?php // quantity of each item $sql1 = 'select `idpentered` , `itemid` , `qty` , `value` `tblpieceentered` `itemid` =307 ' ; echo $sql1."<br>"; // retrieve data table $result1 = mysql_query($sql1) or die(mysql_error()); // store record of table $row1 $row1 = mysql_fetch_array( $result1 ); $i = 1; $num = mysql_num_rows ($result1); echo "num rows: $num <br>"; while ($row1 = mysql_fetch_assoc ( $result1)) { $data_array[$i] = $row1; $i++; } echo "<pre>"; print_r ($data_array); echo "</pre>"; ?>
the result is:
select `idpentered` , `itemid` , `qty` , `value` `tblpieceentered` `itemid` =307 num rows: 5 array ( [1] => array ( [idpentered] => 1999 [itemid] => 307 [qty] => -1 [value] => -0.21 ) [2] => array ( [idpentered] => 2507 [itemid] => 307 [qty] => -10 [value] => -2.1 ) [3] => array ( [idpentered] => 3039 [itemid] => 307 [qty] => 1 [value] => 0.21 ) [4] => array ( [idpentered] => 3040 [itemid] => 307 [qty] => -1 [value] => -0.21 ) )
any ideas?
thanks sean
mysql_fetch_array fetches first row already. don't add row in array. while loop continues second row.
Comments
Post a Comment