Page 1 of 1
Dynamic table structure
Posted: Tue Nov 26, 2002 4:07 am
by brody
I am new to php and I have developed a database with about 8 records. I want to display the data in a table that is only 3 columns wide. As the database grows - the rows of the table would increase but not the columns. As it is written below, the columns increase depending on the number of records I have. Is there an "if" statement I can implement within my code?
<?php
if (!$retid) { echo( mysql_error()); }
else {
while ($row = mysql_fetch_array($retid)) {
$logid = $row["logid"];
$actress = $row["actress"];
$resume = $row["resume"];
echo ("<td bgcolor=#2D2D2D><a href=$logid.html>$logid</a><br>$actress<br><a href=$logid-comments.html>Comments</a></td>\n");
echo ("<td width=6></td><img src=\"../images/spacer.gif\" width=6 height=1></td>\n");
}
}
echo ("</tr><tr><td colspan=5><img src=\"../images/spacer.gif\" width=1 height=10></td></tr>\n");
?>
Any help would be greatly appreciated
Posted: Tue Nov 26, 2002 6:28 am
by Johnm
brody,
Here is an example of how I handled a similar situation:
Code: Select all
<?php
for($x=0;$row=ifx_fetch_row($qry,"NEXT");$x++)
{
echo "<form method=post action=single_unit_sel_sub.php>\n";
////////////////////////////////////////
// Echo break after every third unit. //
////////////////////////////////////////
if (($x != 0) && (($x % 3) == 0))
echo "<tr valign="top">\n";
echo "<td valign="top">\n";
echo "<table border="0" valign="top" align="center">\n";
echo "<tr valign="top">\n";
echo "<td width="33%" align="center">\n";
echo "<h2>".$web_desc."</h2>\n";
echo "<img src="".$image."" height="190" width="190"><br><br>\n";
echo "<b><input type=button Value=Configure
onClick=this.form.submit()></b><br>\n";
include($desc_file);
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</form>\n";
////////////////////////////////////////////
// Echo break after every third unit. //
////////////////////////////////////////
if (($x != 0) && (($x % 3) == 0))
echo "</tr>\n";
}
?>
Hope that helps.
John M
Don't mean to pest, but ...
Posted: Tue Nov 26, 2002 2:28 pm
by brody
Hey Johnm, thanks for the fast reply. I am new to PHP - so bare with me. I tried to implement some of your principles and now my code looks like this:
Code: Select all
<?php
for ($x = 0; $row = mysql_fetch_array($retid); $x++)
{
if (($x != 0) && (($x % 2) == 0))
$actress = $rowї"actress"];
$logid = $rowї"logid"];
echo ("<td bgcolor=#2D2D2D>\n");
echo ("<a href="$logid.html">$logid</a>\n");
echo ("<br>$actress<br>\n");
echo ("<a href="$logid-comments.html">Comments</a></td>\n");
echo ("<td width=6><img src="../images/spacer.gif" width=6 height=1></td>\n");
if (($x != 0) && (($x % 2) == 0))
echo ("</tr><tr><td colspan=5><img src="../images/spacer.gif" width=1 height=10></td></tr>\n");
}
?>
I am running into two problems:
1 - After the first row has 3 columns (that is what I want) the following rows only have 2 columns.
2 - The logid variables are working (they are increasing), however, the actress variables are displaying funny.
http://www.ovadrive.com/php/cadence_table1.php
Again, any additional help is greatly appreciated!
Posted: Wed Nov 27, 2002 6:03 am
by Johnm
Try changing this:
Code: Select all
<?php
if (($x != 0) && (($x % 2) == 0))
?>
to this:
Code: Select all
<?php
if (($x != 0) && (($x % 3) == 0))
?>
in both places. Also, looking at the source in the browser can also clue you in to the problem but this should work.
John M