ericbangug Posted September 12, 2006 Share Posted September 12, 2006 i am having a hard time solving this i have a query result like this[img]http://i29.photobucket.com/albums/c298/nejie/horizontal.jpg[/img]but i want to display it like this:[img]http://i29.photobucket.com/albums/c298/nejie/vertical.jpg[/img]i am still new to php that's why forgive me for my ignorance... thanks alot Quote Link to comment Share on other sites More sharing options...
fenway Posted September 12, 2006 Share Posted September 12, 2006 Not exactly a MySQL question, but I'm not sure how you're generating this, so I don't even know what forum to move it to... Quote Link to comment Share on other sites More sharing options...
ericbangug Posted September 13, 2006 Author Share Posted September 13, 2006 i am using php to generate this kind of table. thanks a lot for replying. :) Quote Link to comment Share on other sites More sharing options...
yaba Posted September 13, 2006 Share Posted September 13, 2006 A very quick and dirty way of doing this:[code=php:0]$rows = $db->query("my query here");while ($r = $rows->fetch_assoc()){ $names[] = $r['name']; $ages[] = $r['age']; $sexes[] = $r['sex']; $addresses[] = $r['address'];}$out = "<tr><td>name</td>";foreach ($names as $n) $out = "<td>".$n[$i]."</td>";$out .= "</tr>";$out .= "<tr><td>age</td>";foreach ($ages as $a) $out = "<td>".$a[$i]."</td>";$out .= "</tr>";$out .= "<tr><td>sex</td>";foreach ($sexes as $s) $out = "<td>".$s[$i]."</td>";$out .= "</tr>";$out .= "<tr><td>address</td>";foreach ($addresses as $a) $out = "<td>".$a[$i]."</td>";$out .= "</tr>";echo "<table>{$out}</table>";[/code]I bet this can be written in a better way, as this is not very efficient. And I haven't run this, maybe there are typos. And the first 2-3 lines assume you are using OO mysqli, you can easily change the way you fetch your rows.Hope this helps ;) Quote Link to comment Share on other sites More sharing options...
ericbangug Posted September 13, 2006 Author Share Posted September 13, 2006 i'll try it right now... message you back if it run smoothly. thanks mate ;) Quote Link to comment Share on other sites More sharing options...
ericbangug Posted September 13, 2006 Author Share Posted September 13, 2006 it worked bro... thanks a lot... ;) ;) ;) ;)[img]http://i29.photobucket.com/albums/c298/nejie/test1.jpg[/img] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.