Jump to content

[SOLVED] setting array key to 1 instead of 0 with mysql_fetch_array


Optimo

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.