PLATFORM:
PHP, mySQL
WHAT I HAVE:
I have a Database table. Within my application, I am able to fetch all the rows. When I am querying the database, I have set the records fetch limit dynamically.
WHAT I AM TRYING TO DO:
I am trying to pull out all the rows of data until the record fetch limit is reached, in a loop. I want to assign these results to another array(in the loop) so that I can access these values via this new array, outside the loop. I need the PHP code to do so. I want to be able to apply the same logic of coding in Javascript. Will that be possible?
EXAMPLE:
//TABLE STRUCTURE
fname lname city
Ed Al SA
Bob B MN
Chris V KJ
PHP QUERY:
$result = mysql_query("SELECT fname, lname, city FROM table LIMIT 3");
while( $row = mysql_fetch_array($result) ) {
$new_rows_data['fname'] .= $row['fname'];
$new_rows_data['lname'] .= $row['lname'];
$new_rows_data['city'] .= $row['city'];
}
DESIRED OUTPUT:
echo $new_rows_data['fname'][0].' '.$new_rows_data['lname'][0].' '.$new_rows_data['city'][0].
//Want the above to show: Ed Al SA
echo $new_rows_data['fname'][1].' '.$new_rows_data['lname'][1].' '.$new_rows_data['city'][1].
//Want the above to show: Bob B MN
echo $new_rows_data['fname'][2].' '.$new_rows_data['lname'][2].' '.$new_rows_data['city'][2].
//Want the above to show: Chris V KJ
Thank you in advance.