Solved

output table php

Posted on 2011-03-16
2
242 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now