php - Grabbing key value from a mysql query -
i thought quite basic reason can't figure out.
i have query
$result = mysql_query("select * users.information limit 0,1");
to grab data (such firstname, lastname), use snippet of code
<?php while ($row = mysql_fetch_assoc($result)): ?> <?php foreach($row $key=>$value) { echo $value; } ?> <?php endwhile; ?>
which correctly prints want.
now in separate table, want have such print individual values separately. thought quite simple like
first name:
however, not work. if $value, of course makes sense, prints last value in array.
how grab individual values? parse $value different values, or there easier way?
thank you.
$data = array() ; //create storage, can access later. <?php while ($row = mysql_fetch_assoc($result)): ?> $data[] = $row ; //add value storage. <?php foreach($row $key=>$value) { echo $value; } ?> <?php endwhile; ?>
we ready. have $data
array rows. can manipulate it, access elements, pass somewhere.
$data[0] ; //access first element echo $data[0]['firstname'] ; //print first name of first row.
Comments
Post a Comment