Page 1 of 1

help displaying sql output in a table

Posted: Wed Feb 04, 2009 11:59 pm
by phpstudent
Brand new to php and trying to get a page that will collect data from sql db and output in a table.

should be two columns, the first being date, second being news.... date and news should be the headers, and then all the information would display in one table. I am getting close, but for some reason, every row of data shows in its own individual table, and the titles keep repeating.

Any ideas what im doing wrong?

Code: Select all

$result_query  = mysql_query($query_ave);
while($row = mysql_fetch_assoc($result_query)){
   
echo "<table border='1'>";
echo "<tr> <th>Date</th> <th>News</th> </tr>";
    echo "<tr><td>"; 
    echo $row['date'];
    echo "</td><td>"; 
    echo $row['news'];
    echo "</td></tr>"; 
} 
echo "</table>";
 

Re: help displaying sql output in a table

Posted: Thu Feb 05, 2009 12:01 am
by Benjamin
This should not be inside the while loop:

Code: Select all

 
echo "<table border='1'>";
echo "<tr> <th>Date</th> <th>News</th> </tr>";
 

Re: help displaying sql output in a table

Posted: Thu Feb 05, 2009 12:04 am
by phpstudent
thanks astions... that worked perfectly

wish i had asked that here about an hour ago :crazy:

do you know how i could limit the news column to a certain width and have text inside wrapping?

anyways, thanks and look forward to learning here, seems like good place for it

Re: help displaying sql output in a table

Posted: Thu Feb 05, 2009 12:10 am
by Benjamin

Code: Select all

 
<td style="width: 400px;">
<!-- OR -->
<td style="width: 80%;">
 

Re: help displaying sql output in a table

Posted: Thu Feb 05, 2009 12:14 am
by phpstudent
awesome, thanks again