Jump to content

[SOLVED] PHP MYSQL Problem with Conditional IF Statement - Novice


ofmyst

Recommended Posts

I have a mysql database with painting info.  My php calls the information.  However, I only want three images per line, right now it will put as many in the line as I have in the database.  I thought the best option was an if statement.  I have an ID field set up, they show T01, T02, T03 etc.  Is there a way to say If ID = T01 - 03 then,  if ID =  T04 - 06, etc?  Or is there a better way to structure this?

 

Here is what it currently looks like:

 

 

mysql_select_db("paintings", $con);

 

$result = mysql_query("SELECT * FROM pieces");

 

 

while($row = mysql_fetch_array($result))

 

  {

  echo "<td align='center' width='27%'>";

  echo "<font color='white'>" . $row['Image'] . "</font><br>";

  echo "<br>";

  echo "<font color='white'>" . $row['Link'] . "</font><br>";

  echo "<font color='white'>" . $row['Title'] . "</font><br>";

  echo "<font color='white'>" . $row['Medium'] . "</font><br>";

  echo "<font color='white'>" . $row['Size'] . "</font>";

  echo "</td>";

  }

 

 

Thank you very much for any help you can offer.

Link to comment
Share on other sites

The basic skeleton of it (using tables) is:

$max = 16; //random made up number
if($max > 0) {
    echo '<table><tr>';
    for($i = 0; $i < $max; ++$i) {
        if($i+1 % 3 == 0) {
            echo '<tr>';
            if($i+1 != $max) echo '<tr>';
        }
        echo '<td>blah</td>';
    }
    for($i = 3-($max%3); $i > 0; --$i) echo '<td></td>';
    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.