Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2002
    Location
    London UK
    Posts
    140

    code snippet - building vertical columns from a mysql result

    Code:
    $result = mysql_query("SELECT * FROM cities ORDER BY city_name") or die ("Failed.".mysql_error()); 
    $num_rows = mysql_num_rows($result);
    $x = 0;
    $num_cols = 4;
    
    print '
    <TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" WIDTH="100%">
    	<TR>
    	<TD VALIGN="TOP">';
    	while($row = mysql_fetch_array($result)) { 
    
    		print $row['city_name']. '<BR>';
    
    		$x++;
    
    		if ($x == ceil($num_rows / $num_cols)) {
    
    			print '
    			</TD>
    			<TD VALIGN="TOP">';
    
    			$x = 0;
    
    		}
    
    	} 
    	print '
    	</TD>
    	</TR>
    </TABLE>';
    $num_cols is the number of columns you want....

    Philco

  2. #2
    thanks ive been loking for something like this for my uncles site, hel be happy in the morning when i give him a link to the site

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •