This is count number of rows and column in table.the single line can be count a table rows this is count a rows and column of your table.it's calculate a rows and column .finally display a how many rows and column presents in your table .
No. of column (3)
Row Count
<?php
$row_count= mysql_query("SELECT * FROM comments", $conn);
echo mysql_num_rows($row_count);
?>
$row_count= mysql_query("SELECT * FROM comments", $conn);
echo mysql_num_rows($row_count);
?>
Column Count:
<?php
$count_column = mysql_query("SELECT * from comments WHERE id = '1'");
echo mysql_num_fields($count_column);
?>
$count_column = mysql_query("SELECT * from comments WHERE id = '1'");
echo mysql_num_fields($count_column);
?>
Source code:
<html>
<head>
<title>Php coding for count table rows</title>
</head>
<?php
$conn= mysql_connect("localhost", "root", "");
mysql_select_db("demo", $conn);
//Row Count
$row_count= mysql_query("SELECT * FROM comments", $conn);
$rows= mysql_num_rows($row_count);
echo " No. of Rows (".$rows.")<br>";
//Column Count
$column_count = mysql_query("SELECT * from comments WHERE id = '1'",$conn);
$column= mysql_num_fields($column_count);
echo "No. of Columns ( ".$column.")";
?>
<body>
</html>
<head>
<title>Php coding for count table rows</title>
</head>
<?php
$conn= mysql_connect("localhost", "root", "");
mysql_select_db("demo", $conn);
//Row Count
$row_count= mysql_query("SELECT * FROM comments", $conn);
$rows= mysql_num_rows($row_count);
echo " No. of Rows (".$rows.")<br>";
//Column Count
$column_count = mysql_query("SELECT * from comments WHERE id = '1'",$conn);
$column= mysql_num_fields($column_count);
echo "No. of Columns ( ".$column.")";
?>
<body>
</html>
Output:
No. of Rows (4 )No. of column (3)
No comments:
Post a Comment