Page 1 of 1

How to create a desire tabular structure with the data comin

Posted: Thu Jun 21, 2007 4:07 pm
by djdon11
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....

Posted: Thu Jun 21, 2007 4:23 pm
by ReverendDexter
You could output it as an html table...

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>";
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

Posted: Thu Jun 21, 2007 5:47 pm
by feyd
Useful Posts links to a two threads which may be of interest. The first two links.