• support@answerspoint.com

How to Create a table 2 to 20 using for loop in php

3869

I want to create table 2 to 20 through for loop in php, but here occure some problem, anyone explain it.

2Answer


0

Use This Code to  Create table 2 to 20 

<html>
    <head>
    <title>Create a table 2 to 20 using for loop in php</title>
    </head>
<body>
	<?php
    	echo "<table border ='1'>";
    	for ($row=1; $row <= 10; $row++) 
		{ 
    		echo "<tr> \n";
			for ($col=1; $col <= 20; $col++) 
			{ 
				$p = $col * $row;
				echo "<td>$p</td> \n";
			}
    		echo "</tr>";
    	}
    	echo "</table>";
    ?>

</body>
</html>

 

  • answered 7 years ago
  • Community  wiki

0
<?php
* connect to the db */
$connection = mysql_connect('localhost','username','password');
mysql_select_db('my_db',$connection);

/* show tables */
$result = mysql_query('SHOW TABLES',$connection) or die('cannot show tables');
while($tableName = mysql_fetch_row($result)) {

	$table = $tableName[0];
	
	echo '<h3>',$table,'</h3>';
	$result2 = mysql_query('SHOW COLUMNS FROM '.$table) or die('cannot show columns from '.$table);
	if(mysql_num_rows($result2)) {
		echo '<table cellpadding="0" cellspacing="0" class="db-table">';
		echo '<tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default<th>Extra</th></tr>';
		while($row2 = mysql_fetch_row($result2)) {
			echo '<tr>';
			foreach($row2 as $key=>$value) {
				echo '<td>',$value,'</td>';
			}
			echo '</tr>';
		}
		echo '</table><br />';
	}
}
?>

 

  • answered 7 years ago
  • Sunny Solu

Your Answer

    Facebook Share        
       
  • asked 7 years ago
  • viewed 3869 times
  • active 7 years ago

Best Rated Questions