Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-05-2012, 04:09 PM   PM User | #1
macbb1117
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
macbb1117 is an unknown quantity at this point
Display Results in Table

I am trying to get the values from a mysql query to display in a table within PHP.

I used this from W3School:

---

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "</tr>";
}
echo "</table>";

Which looks like this.

Heading 1 | Heading 2 | Heading 3
_______________________________________

Value 1 | Value 2 | Value 3

---

But I would like the table to go the other way. Headings going down, each in its own row with values from sql to the right of them.

Heading 1 | Value 1
Heading 2 | Value 2
Heading 3 | Value 3

Attached is an example of what the table needs to look like. Sorry, hard to explain. Thanks!
Attached Thumbnails
Click image for larger version

Name:	table.jpg
Views:	30
Size:	13.9 KB
ID:	11519  
macbb1117 is offline   Reply With Quote
Old 09-05-2012, 04:19 PM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
PHP Code:
echo "<table border='1'>";

while(
$row mysql_fetch_array($result))
{
echo 
"<tr>";
echo 
"<th>Firstname</th>";
echo 
"<td>" $row['FirstName'] . "</td>";
echo 
"</tr>";
echo 
"<tr>";
echo 
"<th>Lastname</th>";
echo 
"<td>" $row['LastName'] . "</td>";
echo 
"</tr>";
}
echo 
"</table>"
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 09-05-2012, 04:27 PM   PM User | #3
macbb1117
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
macbb1117 is an unknown quantity at this point
Wow. I feel really stupid now. I was making that way too complicated. Thanks so much for your quick response!
macbb1117 is offline   Reply With Quote
Reply

Bookmarks

Tags
mysql, php, table

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:19 PM.


Advertisement
Log in to turn off these ads.