[PHP] databases, loops and tables oh my...

2006-02-23 Thread Jason Gerfen
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 
help is appreciated.


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

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

 if( $i % 2 == 0 ) {
  $tr = /trtr;
 }
 if( $scope == no ) {
  $range1 = NULL; $range2 = NULL;
 }
 $subnets .= td valign=\top\ valign=\center\
  table cellspacing=\3\ border=\0\
  trtd colspan=\2\ 
align=\center\bu$vlan/u/b/td/tr

  trtdbSubnet:/b/tdtd$subnet/td/tr
  trtdbMask:/b/tdtd$mask/td/tr
  trtdbDNS:/b/tdtd$dns01/td/tr
  trtdbDNS:/b/tdtd$dns02/td/tr
  trtdbGateway:/b/tdtd$router/td/tr
  trtdbVlan:/b/tdtd$vlan/td/tr
  
trtdbScope:/b/tdtd$range1nbsp;-nbsp;$range2/td/tr

  /table/td . $tr;
$i++;
}
$subnets .= /tr/table;

--
Jason Gerfen

When asked what love is:
Love is the Jager talking.
~Craig Baldo

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



Re: [PHP] databases, loops and tables oh my...

2006-02-23 Thread Jochem Maas

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%\trtd bgcolor=\#C10202\ 
class=\fntTR\ colspan=\$num\Subnets and global parameters for 
each/td/trtr;

$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 = /trtr;
 }


// with this:

$tr = ($i % $numPerRow) ? /trtr : ;


 if( $scope == no ) {
  $range1 = NULL; $range2 = NULL;
 }
 $subnets .= td valign=\top\ valign=\center\
  table cellspacing=\3\ border=\0\
  trtd colspan=\2\ 
align=\center\bu$vlan/u/b/td/tr

  trtdbSubnet:/b/tdtd$subnet/td/tr
  trtdbMask:/b/tdtd$mask/td/tr
  trtdbDNS:/b/tdtd$dns01/td/tr
  trtdbDNS:/b/tdtd$dns02/td/tr
  trtdbGateway:/b/tdtd$router/td/tr
  trtdbVlan:/b/tdtd$vlan/td/tr
  
trtdbScope:/b/tdtd$range1nbsp;-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