Jump to content

Echo'ing SQL Result Over Multiple Table Columns


leachus2002

Recommended Posts

Hi There,

 

I have an SQL query that returns 10 rows, which I want to echo over 2 columns and 5 rows, however, I want rows 1-5 on the left hand column and rows 6-10 on the right hand side.

 

Is there an easy way to do this? Normally I would do a fetch_array but, that would place the rows in order of, left, right, left, right - if that makes sense?

 

Table is a standard table with 2 columns and 5 rows.

 

Thanks

Matt

Link to comment
Share on other sites

Not the most elegant; however, since you are only dealing with 10 records, perhaps something like this...

 

<?PHP
/* connect to db */
include('db.php');

/* create query */
$query = "SELECT * FROM table_name";

/* execute query */
$result = mysql_query($query);

/* put the content into an array */
while($row=mysql_fetch_array($result)) {
$cell_content[] = $row['some_field_name];
}

/* start the table */
echo "<table>";

/* loop thru the array */
$i=0;
while($i<10) {
echo "<tr><td>" . $cell_content[$i] . "</td><td>" . $cell_content[$i+5] . "</td></tr>";
$i = $i +2;
}

/* close the table */
echo "</table>";

?>

Link to comment
Share on other sites

echo " <table width='100%' cellspacing='0' cellpadding='2'><form name='sysstatus' action='index.php' method='post'>";
$i = 1;
while($i<10){
echo "<tr><td width='150'>".$sysname[$i]."</td><td> </td><td width='30'> </td><td width='150'>".$sysname[$i+5]."</td><td> </td></tr>";
$i = $i +2;
}
echo "</form></table>";

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.