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? 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 } 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
Archived
This topic is now archived and is closed to further replies.