Jump to content

[SOLVED] display in multiple columns


peranha

Recommended Posts

I want to display a result in a total of 3 columns.  I have a sql database  and here is the code that I use for it.

 

// create query
$query = "SELECT firstname, lastname, address, city, state, zip FROM testtable";

// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another

while($row = mysql_fetch_row($result)) {

echo "<table>";
echo "<TR>";

	echo "<TD>";
	echo $row[0] . " " . $row[1] . "<BR>";
	echo $row[2] . "<BR>";
	echo $row[3] . ", " . $row[4] . " " . $row[5] . "<BR>";
	echo "<BR>";
	echo "</TD>";

echo "</tr>";
echo "</table>";

 

this puts the info in a single column, and I want to to span into 3 columns. 

 

example

 

Record 1                                                  Record 2                                          Record 3

 

Record 4                                                  Record 5                                          Record 6

Link to comment
https://forums.phpfreaks.com/topic/89834-solved-display-in-multiple-columns/
Share on other sites

begins a new row...

starts a new column

 

you start top to bottom, left to right

 

NEW row

NEW dimension

NEW dimension contents: Record 1

NEW dimension

NEW dimension contents: Record 2

 

 

all the while....keep tabs on whether the Record # is divisible by 3.

if(($rec_id % 3)) == false

 

if it's true

you need a new row

 

NEW row

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.