Jump to content

MYSQL_BOTH does not work correctly


markyoung1984

Recommended Posts

I must be doing something wrong.  I have the following code:

 

				while($row = mysql_fetch_array($result,MYSQL_BOTH))
				{
					for($i=0;$i<$this->numOfFields;$i++)
					{
                                                      $dbResults[mysql_field_name($result,$i)] = $row[$i]; 
                                                }
				}

 

As you can see I am using the MYSQL_BOTH array constant, because I want to use both associative and numerical indices, however the numberical part does not seem to work e.g.

 


echo $dbResults['myColumnName'];  //this works fine with the above code
echo $dbResults[1];  //this does not work at all!!

 

I was under the impression by using MYSQL_BOTH that I could switch between the numerical and associative indices.  Is this not correct?

Link to comment
Share on other sites

yes, $row will contain an array with both associative and numerical indices. but, you are looping through and only setting the associative ones into $dbResult. no matter how you look at it, i don't see the need for the for loop:

 

while($row = mysql_fetch_array($result,MYSQL_BOTH))
{
   $dbResults = $row;
   //Now $dbResult will contain all the info you want
   //But the above is also pointless as you can just just use $row
}

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.