Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

output table php

Posted on 2011-03-16
2
Medium Priority
?
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

715 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