Re: databases, loops and tables oh my...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jason Gerfen wrote:
Not sure about this one, I am trying to execute a SQL query to retrieve records then loop over the records and display X amount per line. Any

X ammount of what per 'line'? db records (or elelphants)?
and by line do you mean 'html table row'?

assuming I got that correct, check my comments below
(hopefully it's understandable):

help is appreciated.

$sql = @mysql_query( "SELECT * FROM subnets", $db );
$num = @mysql_num_rows( $sql );
$subnets .= "<table width=\"100%\"><tr><td bgcolor=\"#C10202\" class=\"fntTR\" colspan=\"$num\">Subnets and global parameters for each</td></tr><tr>";
$i = 1;

// add the following line here:

$numPerRow = 3; // number of records to show per table row.

while( $list = @mysql_fetch_array( $sql ) ) {
list( $id, $subnet, $mask, $dns01, $dns02, $router, $vlan, $scope, $range1, $range2, $vlan ) = $list;

// and replace this if():

 if( $i % 2 == 0 ) {
  $tr = "</tr><tr>";
 }

// with this:

$tr = ($i % $numPerRow) ? "</tr><tr>" : "";

 if( $scope == "no" ) {
  $range1 = "NULL"; $range2 = "NULL";
 }
 $subnets .= "<td valign=\"top\" valign=\"center\">
                          <table cellspacing=\"3\" border=\"0\">
<tr><td colspan=\"2\" align=\"center\"><b><u>$vlan</u></b></td></tr>
                          <tr><td><b>Subnet:</b></td><td>$subnet</td></tr>
                          <tr><td><b>Mask:</b></td><td>$mask</td></tr>
                          <tr><td><b>DNS:</b></td><td>$dns01</td></tr>
                          <tr><td><b>DNS:</b></td><td>$dns02</td></tr>
                          <tr><td><b>Gateway:</b></td><td>$router</td></tr>
                          <tr><td><b>Vlan:</b></td><td>$vlan</td></tr>
<tr><td><b>Scope:</b></td><td>$range1&nbsp;-&nbsp;$range2</td></tr>
                          </table></td>" . $tr;
$i++;
}
$subnets .= "</tr></table>";


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux