Jump to content

Recommended Posts

I have this code and currently the records are going down in rows. I would like the records to appear across next to one another and be able to adjust the number of columns if I'd like. Hope someone can help

 

<table border="1" align="center">

  <?php do { ?>

    <tr>

      <td><a href="questiondetails.php?recordID=<?php echo $row_sixities['ID']; ?>"> <?php echo $row_sixities['item']; ?> <br />

      <?php echo $row_sixities['image_tb']; ?>      </a></td>

    </tr>

    <?php } while ($row_sixities = mysql_fetch_assoc($sixities)); ?>

</table>

Link to comment
https://forums.phpfreaks.com/topic/205592-mulitply-columns/
Share on other sites

<?php
//Var to adjust number of columns
$max_columns = 6;
  
function create_row($row_data)
{
    if(count($row_data)<1) { return false; }
    $row_output = "<tr>\n";
    foreach($row_data as $row)
    {
        $row_output .= "<td>";
        $row_output .= "<a href=\"questiondetails.php?recordID={$row['ID']}\">{$row['item']}<br />\n";
        $row_output .= "{$row['image_tb']}</a>\n";
        $row_output .= "</td>\n";
    }
    $row_output .= "<tr>\n";
    return $row_output;
}

$current_col = 0;
$row_data = array();
$table_output = '';
while($row_sixities = mysql_fetch_assoc($sixities))
{
    $current_col++;
    $row_data[] = $row_sixities;
    if($current_col%6==0)
    {
        $table_output .= create_row($row_data);
        $row_data = array();
    }
}
$table_output .= create_row($row_data);

?>
<table border="1" align="center">
  <?php echo $table_output; ?>
</table>

Link to comment
https://forums.phpfreaks.com/topic/205592-mulitply-columns/#findComment-1076212
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.