php - Separating mysql fetch array results -
i have mysql table contains index id, data entry , 10 other columns called peso1, peso2, peso3...peso10. im trying last 7 peso1 values specific id. like:
$sql = mysql_query("select * table id='$id_a' order data desc limit 0, 7");
when try fetch values mysql_fetch_array, values together.
example:
while($line = mysql_fetch_array($sql)) { echo $line['peso1']; }
i peso1 values 7 days together. how can separated?
they appear because not separating them loop through them.
for example, insert line break , see them on separate lines
while($line = mysql_fetch_array($sql)) { echo $line['peso1'] ."<br />"; }
you key array so
$myarray = array(); $i = 1; while($line = mysql_fetch_array($sql)) { $myarray['day'.$i] = $line['peso1']; $i++; }
example use
$myarray['day1'] // returns day 1 value $myarray['day2'] // returns day 2 value
Comments
Post a Comment