columns

This is a discussion on columns within the PHP Language forums, part of the PHP Programming Forums category; Hi All I posted in a while ago abot displaying the results of a query in 4 columns. The piece ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-08-2005
Andy Jacobs
 
Posts: n/a
Default columns

Hi All

I posted in a while ago abot displaying the results of a query in 4
columns. The piece of code I was given works fine:

<table width="100%" border="0" cellspacing="0" cellpadding="10">
<?php
do {
$tr = !(++$row % 2);
if (!$tr) print "<tr>";
?>
<td width="100">
<div align="center">
<a href="productdetail.php?id=<?php echo $row_Recordset1['id']; ?>">
<img src="/user_thumbs/<?php echo $row_Recordset1['file']; ?>"
border="0"></a>
</div>
</td>
<td><?php echo $row_Recordset1['title']; ?>
</td>
<?php if ($tr) print "</tr>";
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
if (!$tr) print "</tr>";
?>
</table>

I'm doing something else at the moment and I want more columns so I
thought easy, just change:

$tr = !(++$row % 2);

to

$tr = !(++$row % 4);

But it would appear that I missed the plot somewhere.

Can someone throw any light on this please.

Cheers

Andy
Reply With Quote
  #2 (permalink)  
Old 01-09-2005
Kartic
 
Posts: n/a
Default Re: columns

Andy,

That ($row % 2 construct) is used to detect the start and end of the
<tr> tags. So, changing $row$ % 2 to $row % 4 will not do what you
want.

(see how $tr variable is used to detect whether to output <tr> or
</tr>)

To have additional columns, you will have to add the <td></td> pairs
for your extra columns. Please pick up an HTML book to see how tables
are constructed.

<td width="100">
<div align="center">
<a href="productdetail.php?id=<?php echo $row_Recordset1['id'];
?>">
<img src="/user_thumbs/<?php echo $row_Recordset1['file']; ?>"
border="0"></a>
</div>
</td>
<td><?php echo $row_Recordset1['title']; ?>
</td>
<! -- this part is new -->
<td><?php echo $row_Recordset1['columnX']; ?></td>
<td><?php echo $row_Recordset1['columnY']; ?></td>

Thanks,
--Kartic
PS: The code you posted only displays 2 table columns thought it uses 3
columns from your query result.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:52 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0