1) Count record:
//Connect to mysql server
$link = mysql_connect(HOST, USER, PASSWORD);
if(!$link) {
die('Could not connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DATABASE);
if(!$db) {
die("cannot use the database");
}
mysql_set_charset('charset=utf8',$link);
$query="SELECT `id`FROM `table` WHERE `abc`='123'";
$result=mysql_query($query);
$count= mysql_num_rows($result);
I am using this to count the record. The table has 500K records. What is the best practice to count the records?
2) I am beginner @ mysql and php. Did I miss something in the above script? I think I need to close mysql connection in the end !
mysql has a count function:
http://dev.mysql.com/doc/refman/5.1/en/counting-rows.html
so you could use:
or whatever condition.