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
https://forums.phpfreaks.com/topic/135351-mysql_both-does-not-work-correctly/
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
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.