Solved

output table php

Posted on 2011-03-16
2
247 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 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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 count occurrences of each item in an array.

752 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