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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.