Jump to content

[SOLVED] Making Columns


The Little Guy

Recommended Posts

I have a page that displays items according to values in the database.

 

So... I have a column in the database called 'column'. Column tells what column to place the item in. I am having problems creating the columns on the page.

 

$sql = mysql_query("SELECT * FROM userWidgets u LEFT JOIN widgets w ON (u.widget = w.id) WHERE owner = '$_id' ORDER BY `column`, `row`");
while($row = mysql_fetch_array($sql)){

}

 

I am not sure how to code within the loop to make column one and column two.

 

Both columns can contain 1 or more items, so any help?

Link to comment
Share on other sites

It's easier to code this than store it into a database. This is just pseudo code so it may need modifying to work but the basics are there. That and I'm mixing HTML with PHP but that's besides the point, it gets the basics out ;)

 

<?php
$columns = 2;
$total_records = 20;
$column_split = ceil($total_records / $columns);

echo '<table><tr>';
while ($row = mysql_fetch_array($sql)) {
  $count++;

  echo '<td>' . $row['tablerow'] . '</td>';

  if ($count == $column_split) {
    echo '</tr><tr>';
    $count = 0;
  }
}
echo '</tr></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.