PHP HTML Formatting
Posted: Wed Feb 26, 2003 11:18 am
Hi All,
I am new to this forum, and would really appreciate if someone can help me with this.
What it is I am using php to fetch the results and display only 8 on the page, now I know how to get the results etc.. but the formatting on the page is where my problem lies.
If you look at the code for my page here, just the section I need. You will see that if I limit the results to 8 they print straight across the page, what I need is for 4 columns to print across then to loop and print another row with 4 columns so we have two rows of four columns, but I am unsure how to do this, as i have always worked with rows and never having to do this in columns.
Here is my code:
<?
//BZDP PHP Connect Code:
$user = "*****";
$pass = "*****";
$db = "*****";
$link = mysql_pconnect( "localhost", $user, $pass );
if ( ! $link)
die( "Couldn't connect to MySQL" );
mysql_select_db( $db, $link )
or die ("Couldn't open $db: ".mysql_error() );
$sql= "SELECT * FROM clients ORDER BY id DESC LIMIT 8";
$sql_result = mysql_query($sql);
if (mysql_num_rows($sql_result) ==0)
{
echo (" <P></P>\n");
}
else {
?>
<TR VALIGN=TOP>
<TD></TD>
<TD>
<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2>
<TR>
<?
while ($row = mysql_fetch_array($sql_result)){
echo (" <TD HEIGHT=137 WIDTH=194 VALIGN=TOP>\n");
echo (" <P><FONT FACE=\"Verdana\" SIZE=2><SPAN CLASS=\"style18\"><B>$row[clientname]</B></SPAN></FONT></P>\n");
echo (" <P><FONT FACE=\"Verdana\" SIZE=2><SPAN CLASS=\"style18\"><IMG SRC=\"Resources/portfo3.gif\" BORDER=0 WIDTH=189 HEIGHT=81 ALIGN=ABSBOTTOM HSPACE=0 VSPACE=0></SPAN></FONT><FONT FACE=\"Verdana\" SIZE=2><SPAN CLASS=\"style18\"></SPAN></FONT></P>\n");
echo (" <P><FONT FACE=\"Verdana\" SIZE=2><SPAN CLASS=\"style18\">$row[description]</SPAN></FONT></P></TD>\n");
}
}
?>
</TR>
<TR>
<TD HEIGHT=9 WIDTH=782 COLSPAN=4 VALIGN=TOP><IMG SRC="Resources/_clear.gif" BORDER=0 WIDTH=1 HEIGHT=1 ALT=""></TD>
</TR>
</TABLE>
END CODE -------
You can see that the 8 entries go across the page. I need to show 4 then another 4 underneath.
Appreciate if anyone can help.
I am new to this forum, and would really appreciate if someone can help me with this.
What it is I am using php to fetch the results and display only 8 on the page, now I know how to get the results etc.. but the formatting on the page is where my problem lies.
If you look at the code for my page here, just the section I need. You will see that if I limit the results to 8 they print straight across the page, what I need is for 4 columns to print across then to loop and print another row with 4 columns so we have two rows of four columns, but I am unsure how to do this, as i have always worked with rows and never having to do this in columns.
Here is my code:
<?
//BZDP PHP Connect Code:
$user = "*****";
$pass = "*****";
$db = "*****";
$link = mysql_pconnect( "localhost", $user, $pass );
if ( ! $link)
die( "Couldn't connect to MySQL" );
mysql_select_db( $db, $link )
or die ("Couldn't open $db: ".mysql_error() );
$sql= "SELECT * FROM clients ORDER BY id DESC LIMIT 8";
$sql_result = mysql_query($sql);
if (mysql_num_rows($sql_result) ==0)
{
echo (" <P></P>\n");
}
else {
?>
<TR VALIGN=TOP>
<TD></TD>
<TD>
<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2>
<TR>
<?
while ($row = mysql_fetch_array($sql_result)){
echo (" <TD HEIGHT=137 WIDTH=194 VALIGN=TOP>\n");
echo (" <P><FONT FACE=\"Verdana\" SIZE=2><SPAN CLASS=\"style18\"><B>$row[clientname]</B></SPAN></FONT></P>\n");
echo (" <P><FONT FACE=\"Verdana\" SIZE=2><SPAN CLASS=\"style18\"><IMG SRC=\"Resources/portfo3.gif\" BORDER=0 WIDTH=189 HEIGHT=81 ALIGN=ABSBOTTOM HSPACE=0 VSPACE=0></SPAN></FONT><FONT FACE=\"Verdana\" SIZE=2><SPAN CLASS=\"style18\"></SPAN></FONT></P>\n");
echo (" <P><FONT FACE=\"Verdana\" SIZE=2><SPAN CLASS=\"style18\">$row[description]</SPAN></FONT></P></TD>\n");
}
}
?>
</TR>
<TR>
<TD HEIGHT=9 WIDTH=782 COLSPAN=4 VALIGN=TOP><IMG SRC="Resources/_clear.gif" BORDER=0 WIDTH=1 HEIGHT=1 ALT=""></TD>
</TR>
</TABLE>
END CODE -------
You can see that the 8 entries go across the page. I need to show 4 then another 4 underneath.
Appreciate if anyone can help.