Optimo Posted November 12, 2007 Share Posted November 12, 2007 as the topic states i have a mysql statement that is selecting many records from a DB and then im using them in an array later and in a for loop where $x changes thus changing the array data but i want the array to start form key 1 instead of key 0 i know theirs an easy way to do it as with other languages but im pretty new to arrays and ive not been able to find it on php.net here and example of how my code works: $sql = mysql_query("SELECT * FROM __________") or die(mysql_error()); while($row = mysql_fetch_array($sql)) {$unit_data_array[] = $row;} for($x = 1; $x < 17; $x++) { $unit_data = $unit_data_array[$x]; $unit_name = $unit_data[name]; $unit_crew = $unit_data[crew]; $unit_type = $unit_data[type]; $unit_money = $unit_data[money]; $unit_deterium = $unit_data[deterium]; ........ } and $x = 1 is displaying data from the 2nd record in the array and i want it to show the 1st record. any help would be great thanks Quote Link to comment Share on other sites More sharing options...
Barand Posted November 12, 2007 Share Posted November 12, 2007 You could always add element 0 first $sql = mysql_query("SELECT * FROM __________") or die(mysql_error()); $unit_data_array[0] = ''; while($row = mysql_fetch_array($sql)) {$unit_data_array[] = $row;} Quote Link to comment Share on other sites More sharing options...
Optimo Posted November 12, 2007 Author Share Posted November 12, 2007 thanks i knew it was something as simple as that Quote Link to comment Share on other sites More sharing options...
Barand Posted November 12, 2007 Share Posted November 12, 2007 BTW, if you are storing each row in an array like that I'd use either mysql_fetch_row() mysql_fetch_assoc() Using mysql_fetch_array() without optional second argument stores each column value twice. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.