markyoung1984 Posted December 3, 2008 Share Posted December 3, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/135351-mysql_both-does-not-work-correctly/ Share on other sites More sharing options...
rhodesa Posted December 3, 2008 Share Posted December 3, 2008 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 } Quote Link to comment https://forums.phpfreaks.com/topic/135351-mysql_both-does-not-work-correctly/#findComment-705045 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.