Jump to content

[SOLVED] columns


rdub

Recommended Posts

I'd like these results to display in two columns:

 

<?

 

//select the table

$result = mysql_query("select * from properties where Sale like '%yes%'");

 

//grab all the content

while($row=mysql_fetch_assoc($result)) {

 

 

 

 

?>

 

 

 

 

<table width="200" align="center" class="sample">

  <tr>

    <td width="533"><table width="200" border="0" align="center" cellpadding="2" cellspacing="0">

      <tr>

        <td width="200" align="center" valign="top"><img src='<? echo $row['Image']; ?>' alt="table"

  height="140" width="200" /><br> <span class="style1a">'<? echo $row['hi_lite']; ?>'</span></td>

        </tr>

     

     

      <tr>

        <td width="200" align="center" valign="middle" class="style3"><span class="style1b"><? echo $row['Description']; ?></span></td>

        </tr>

      <tr>

        <td width="200" align="center" valign="middle" class="style3">

<?

if( $row['Web'] != "") {

echo '<a href="'.$row['Web'].'" target="_self">click here</a>';

}

?>

</td>

      </tr>

    </table></td>

  </tr>

</table>

 

 

 

  <?

// End While statement

}

 

 

// Close database connection.

//mysql_close();

?>

Link to comment
Share on other sites

Maybe this is closer to what you want...I removed a bunch of formatting as it was getting in my way, you can add it back as you need.  In your while loop you started and ended your table, so there were many tables created.  Then you had a table within a table.  I removed one of them.  Now you have 3 columns. 

1) $row['Image']

2) $row['Description']

3) If there is a link print it, if not print a space (td's don't like to be empty, so put a space in there)

 

oh, and always use full php tags, not <? short tags.

<?php
//select the table
$result = mysql_query("select * from properties where Sale like '%yes%'");

echo '<table width="200" align="center" class="sample">';

//grab all the content
while($row=mysql_fetch_assoc($result)) {
?>
    <tr>
        <td><img src="<?php echo $row['Image']; ?>" /><br><span><?php echo $row['hi_lite']; ?></span></td>
        <td><span><?php echo $row['Description']; ?></span></td>
        <td width="200" align="center" valign="middle" class="style3">
            <?php
                if( $row['Web'] != "") {
                    echo '<a href="'.$row['Web'].'" target="_self">click here</a>';
                } else { echo " "; }
            ?>
        </td>
    </tr>
<?php

} // End While statement
echo '</table>';

// Close database connection.
//mysql_close();
?> 

Link to comment
Share on other sites

I think your main problem was that you had a table in the while loop so you were just created a bunch of tables.  Also, like cronix said, when you have an empty column do it like this

 .
Link to comment
Share on other sites

Obviously I'm not being clear enough. As you can see from the code, the query results "print" within a table, one record below another. If there are 10 records in the database table then they print one below the other until all 10 are seen. I would like for the table containing the results to "print/echo"  in two to three columns rather than one below the other. With two columns the same 10 records would print two across and 5 down.

 

I apologize if I'm not explaining this correctly.

Link to comment
Share on other sites

Ah ok sorry.  You should get the number of results and when you reach over half start a new column.  I don't know if it's the best way to do it but I should work.

 

$half = mysql_num_rows($result)/2;
while(...){
.
.
if($t > $half) { echo ""; }

$t++;
}

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.