Jump to content

Recommended Posts

Hey Everyone,

I'm creating a site that will show images uploaded for certain days working on a job site. Kind of a day-to-day photo journal for the customer. On the site, the user gets here, sees 3 large images, and a series of thumbnails if more than 3 images exist for that day (works fine).

However, underneath that I want to display a 3-4 column setup of "Archived Dates" that provide a link to the images of the other dates. I have this working correctly, but the results are displayed as follows:

 

Date 1: Date 2: Date 3:

 

etc....

 

I want them to display like this;

Day 1 Day 4

Day 2 Day 5

Day 3 Day 6

 

and so on..... in a 3 column format. Here is the code I have right now just looping through to display these link results, not the rest of the page. I am trying to do it tableless right now, but if that isn't the right way to go, please let me know.

Thanks to anyone in advance,

Nick

 

 $SQLRowe = "SELECT DISTINCT RoweImgDate from tblRowe WHERE RoweImgDate !='" . $_GET['date'] . "' Order by RoweImgDate DESC Limit 0, 30";
        //echo $SQLRowe;
        $rsSQLRowe = mysql_query($SQLRowe);

<span class="rowe">Archived Photos:</span><br/>
                    <div id="archive">
                    <?php
                    
                        while($row = mysql_fetch_array($rsSQLRowe)){

                            //echo "<a href='index.php?id="' . $row[RoweImgID] . '"' class='link'>$row[RoweImgDate]</a></br>";
                                    echo "<div id='archivedates'>";
                                    echo "<a href='index.php?date=" . $row[RoweImgDate] . "' class='link'>$row[RoweImgDate]</a>";
                                    echo "</div>";
                                    //echo "<img src='images/$row[RoweImage]'/><br/>";
                                    //echo "<span class='FeatDesc'><p>$row[RoweImgDesc]</p></span><br/>";
                                }
                    ?>
                    </div>

Link to comment
https://forums.phpfreaks.com/topic/214618-display-mysql-results-as-3-column-table/
Share on other sites

i use this, i found on the net. you can adjust it for mysql results:

 

 

/// PUT DATA IN ROWS INSTEAD OF COLUMNS //////////$items = array('ALABAMA','ALASKA');//create an array with your data// Default # of Columns$numcols = 4;// Number of Items$numitems = count($items);// Number of Rows$numrows = ceil($numitems/$numcols);echo '<table>';for ($row=1; $row <= $numrows; $row++) {$cell = 0;echo ' <tr>'."\n";for ($col=1; $col <= $numcols; $col++) {	echo '  <td>'."\n";	if ($col===1) {		$cell += $row;		print $items[$cell - 1];	} else {		$cell += $numrows;		print $items[$cell - 1];	}	echo '  </td>'."\n";}echo ' </tr>'."\n";}echo '</table>';

 

This isn't something complex:

 

echo '<div style="float: left;">', "\n";

$i = 1; $total_per_column = 20;
while($row = mysql_fetch_assoc($result)) {
    if(($i % $total_per_column) == 0) {
        echo '</div>', "\n", '<div style="float: left;">', "\n";
    }
    // echo whatever you want it to look like
    ++$i;
}

echo '</div>';

 

It's adviced to calculate $total_per_column based on the result set (or limit the result set).

hey guys thanks for the suggestions, unfortunately, i'm not able to get either of them working.  BlueSky, I can't seem to get the array to properly store all the values from the SQL result rows, only 1 value is being stored in the $items array.

 

ignace: it seems like you're code leaves at least one of the <div> tags open when it is executed, I got yours to begin displaying how I wanted but it would only display the first and 4th results, as i set the num of rows per column to only 3, displaying like this;

 

1                                                      4

 

instead of:

 

1                                                    4

2

3

thanks again for the help guys, ill keep plugging

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.