Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/136244-converting-mysql-get-array-to-php-array/
Share on other sites

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'];
}

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

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
}

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.