jarmstro12
asked on
output row from mysql table
Do I need to use some storage object to do this?
I have a mysql table TimeTable
user day start end
jim 1 800 400
jim 2 700 300
jim 3 600 200
I would like to output a row -
user start1 end1 start2 end2 start3 end3
jim 800 400 700 300 600 200
I have a mysql table TimeTable
user day start end
jim 1 800 400
jim 2 700 300
jim 3 600 200
I would like to output a row -
user start1 end1 start2 end2 start3 end3
jim 800 400 700 300 600 200
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$users[] where $users["jim"] will contain data for user jim
User's data itself can be also an array, so:
$users["jim"]["start1"] = 800;
$users["jim"]["end1"] = 400;
$users["jim"]["start2"] = 700;
$users["jim"]["end2"] = 300;
(I assume that start1 means start for day 1 from your table)
here is the code:
$result = mysql_query("select * from TimeTable order by day");
while ($row = mysql_fetch_array($result)
$user[$row[user]]["start$r
$user[$row[user]]["end$row
}
?>
<p><b>Let's print array in human readable format:</b><br>
<pre>
<?
print_r($user);
?>
</pre>
<p><b>Print formatted rows for users:</b><br>
<?
foreach ($user as $username => $data) {
print "$username: ";
print join(" ",$data);
print "<br>";
}
?>