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
https://forums.phpfreaks.com/topic/127614-solved-columns/
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
https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-660634
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
https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-661114
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
https://forums.phpfreaks.com/topic/127614-solved-columns/#findComment-661123
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.