Total Number in the Database
- ID: PHP - 14
- Date Added: 2007-12-22
- Category: PHP
- Difficulty: Novice
- Author: Rei
This tutorial will require the use of Phpmyadmin, your php page, and a basic knowledge of php/mysql. This is the code you add to your page:
<?php
$user="admin"; // replace admin with username
$pass="password"; // replace password with yours
$hostname="localhost"; // hostname is 'usually' localhost
$dbase='databasename'; // replace databasename with yours
$connection = mysql_connect ("$hostname" , "$user" , "$pass");
mysql_select_db("databasename");
// Counting the number of rows
$count = "select * from yourtable ";
$result = mysql_query($count);
$num = mysql_num_rows($result);
echo "$num";
?>
The top portion you should already have on your page. The second part (// Counting the number of rows) shows the process of counting all the rows in the specific table. Lastly, echo "$num"; can be inserted anywhere on the page as long as it is after the php code. Basically, this is the code that displays how many rows there are in the database.« back · clear ¦ reload · forward »
Akatsuki Designs © Rei [2006-2008]. Site, layout, and content © Rei. All rights reserved. Valid CSS and HTML Fight Spam! | Spot a typing error? | HostTracker



