phpdolan Posted December 9, 2008 Share Posted December 9, 2008 Looking for help with converting the results from this: $query_get = "SELECT empNum, aaPass, subsDate, bidStatus FROM User"; which will return all the users in the User db, into a php array. Then using: while ( $row = mysql_fetch_array ( $result_get ) )..... I'm having trouble with the mysql array pointer. It seems every time it's referenced, $row['empNum'] advances to the next value. Can anyone explain how to avoid this with the mysql array or to load them into php array. I've tried both several times with no success. I'd like to learn both ways. Thanks, David Quote Link to comment https://forums.phpfreaks.com/topic/136244-converting-mysql-get-array-to-php-array/ Share on other sites More sharing options...
rhodesa Posted December 9, 2008 Share Posted December 9, 2008 so, are you just trying to do: $query_get = "SELECT empNum, aaPass, subsDate, bidStatus FROM User"; $result_get = mysql_query($query_get) or die(mysql_error()); while ( $row = mysql_fetch_array ( $result_get ) ){ $rows[] = $row; print $row['empNum']; } Quote Link to comment https://forums.phpfreaks.com/topic/136244-converting-mysql-get-array-to-php-array/#findComment-710739 Share on other sites More sharing options...
fenway Posted December 9, 2008 Share Posted December 9, 2008 Apparently so. Quote Link to comment https://forums.phpfreaks.com/topic/136244-converting-mysql-get-array-to-php-array/#findComment-710748 Share on other sites More sharing options...
phpdolan Posted December 10, 2008 Author Share Posted December 10, 2008 Thanks for your reply rhodesa. $rows[] = $row; print $row['empNum']; Yes, I think so, if the $rows[] is a php array. My script is using curl, and as it executed, it was stepping to the next value(s) for $row. (It must be due to my missing understanding of this fetched array) I will have to print_r $rows to see how that array is constructed. Is the print $row['empNum'] code using the mysql array? I will research the fetch_array function and give this code a spin. What if I wanted to use $row further down and more than once in a script? Would I have to account for the pointer and the different way that the array is stored with -> mysgl_fetch_array? Thanks for helping me out, David Quote Link to comment https://forums.phpfreaks.com/topic/136244-converting-mysql-get-array-to-php-array/#findComment-711508 Share on other sites More sharing options...
trq Posted December 10, 2008 Share Posted December 10, 2008 mysql_query returns a result resource (not an array) containing all records found using your query. You then loop through the result resource callingmysql_fetch_accoc which in turn returns an array containing each field within the record. Quote Link to comment https://forums.phpfreaks.com/topic/136244-converting-mysql-get-array-to-php-array/#findComment-711518 Share on other sites More sharing options...
rhodesa Posted December 10, 2008 Share Posted December 10, 2008 mysql_fetch_* (there are a few fetch functions) returns a row of data, then moves the 'cursor' to the next row. while ( $row = mysql_fetch_array ( $result_get ) ){ //$row is now an array for one of the rows print_r($row); $row = mysql_fetch_array($result_get); //Returns the NEXT row, not the same row print_r($row); //this will print different data then the print_r() two lines above here } Quote Link to comment https://forums.phpfreaks.com/topic/136244-converting-mysql-get-array-to-php-array/#findComment-711526 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.