Hello Friends.....
I am here to find some code which can show my data which is coming from database in a desirable tabular form..
Means when while loops creates new row for each record .. instead of that i want to create new column for the next record & i want 3 column in a row & after that a new row should be creat....
can anybody help me for this...........
vaibhav....
How to create a desire tabular structure with the data comin
Moderator: General Moderators
- ReverendDexter
- Forum Contributor
- Posts: 193
- Joined: Tue May 29, 2007 1:26 pm
- Location: Chico, CA
You could output it as an html table...
something along the lines of
Not promising that will work 100% right as-is, I copied/pasted and edited it down, but I hope it helps get you started!
-Dex
something along the lines of
Code: Select all
$sql = $your_query;
$result_set = mysql_query($sql);
$cur_row = mysql_fetch_assoc($result_set);
$headrow = "<tr>";
$firstrow = "<tr>";
//open the table
echo "<table><tbody>";
//get headers and first row
foreach($cur_row as $header => $value)
{
$headrow .= "<th>$header</th>";
$firstrow .= "<td>$value</td>";
}
$headrow .= "</tr>";
$firstrow .= "</tr>";
echo "$headrow"."$firstrow";
//Get all other rows
while ($cur_row = mysql_fetch_assoc($result_set))
{
$output_row = "<tr>";
foreach($cur_row as $h=>$value)
{
$output_row .= "<td>$value</td>";
}
$output_row .="</tr>";
echo $output_row;
}
else
{
echo "<tr><td>No rows returned</td></tr>";
}
//close the table
echo "</tbody>
</table>";-Dex