Solved

output table php

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Use Select Query to Return Results as a Form 9 41
Inserting results of While loop to sql server 5 34
Wordpress and Wufoo 1 36
Dump data from mysql to xls php 10 16
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
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.

685 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