Solved

output table php

Posted on 2011-03-16
2
245 Views
Last Modified: 2012-08-13
i have a table that outputs my results from a query.
i am having trouble figuring out how to change how it is displayed.

this is how it looks now: table

i would like it to be output in this way:
id then a break
username then a break
comment

so its vertically instead of horizontally showing the data.
please can anyone advise on how to do this please
$row_count = 0;
$output = '<table width="600" border="0" cellpadding="3" cellspacing="0" class="table1"><tr><td width="41" align="center" bgcolor="#3366CC"><span class="style1">PostID</span></td><td width="149" align="center" bgcolor="#3366CC"><span class="style1">Name</span></td><td width="384" align="center" bgcolor="#3366CC"><span class="style1">Comment</span></td></tr>';
$result = mysql_query("SELECT PostID, PostText FROM posts",$db) or die (mysql_error());
While( $rows = mysql_fetch_array($result)) {
$PostID = $rows['PostID'];
$PostText = $rows['PostText'];

$row_style = ($row_count % 2) ? "row1" : "row2";
$output .= '<tr class="'.$row_style.'"><td>'.$PostID.'</td><td>'.$PostText.'</td></tr>';
$row_count = $row_count + 1;
}
//Free Results
mysql_free_result($result);
$output .= '</table>';
?>

from_mysql_obj = document.getElementById( 'from_mysql' );
from_mysql_obj.innerHTML = '<? echo $output; ?>';

Open in new window

0
Comment
Question by:helpchrisplz
2 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 35154204
$result = mysql_query("SELECT PostID, PostText FROM posts",$db) or die (mysql_error());
While( $rows = mysql_fetch_array($result)) {
$PostID = $rows['PostID'];
$PostText = $rows['PostText'];

//$row_style = ($row_count % 2) ? "row1" : "row2";
$output .= '<tr class="'.$row_style.'"><td>'.$PostID.'</td></tr>';
$output .= '<tr><td>'.$PostText.'</td></tr>';
$row_count = $row_count + 1;
}

Open in new window


But there is no query selection for the name, you would have to add this to the query
0
 
LVL 1

Author Comment

by:helpchrisplz
ID: 35157194
yes name will be done soon. thx roads  :)

here is what it looks like now after tinker time still need to fix up the css but that will be easy:

 update
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question