manalnor Posted March 28, 2010 Share Posted March 28, 2010 Hi, if i've database table as following CREATE TABLE `names` ( `id` bigint(20) unsigned NOT NULL auto_increment, `name` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=215 ; INSERT INTO `names` VALUES (1, 'name1'); INSERT INTO `names` VALUES (2, 'name2'); how to acount number of names so i can write like this Total names : 2 if there any something called count function Quote Link to comment https://forums.phpfreaks.com/topic/196781-count-it/ Share on other sites More sharing options...
salathe Posted March 28, 2010 Share Posted March 28, 2010 if there any something called count function Sure, you can use the COUNT function in a query. See http://dev.mysql.com/doc/refman/5.5/en/counting-rows.html Quote Link to comment https://forums.phpfreaks.com/topic/196781-count-it/#findComment-1033036 Share on other sites More sharing options...
manalnor Posted March 28, 2010 Author Share Posted March 28, 2010 Actually yes. Google it. thanks $sql="SELECT COUNT(id) FROM names"; $cus=mysql_query($sql) or die($sql); $count=mysql_fetch_array($cus); now how to write php code that shows the count number from that table ? Quote Link to comment https://forums.phpfreaks.com/topic/196781-count-it/#findComment-1033041 Share on other sites More sharing options...
mattal999 Posted March 28, 2010 Share Posted March 28, 2010 $sql = "SELECT COUNT(id) AS totalid FROM names"; $cus = mysql_query($sql) or die($sql); $count = mysql_fetch_array($cus); echo $count['totalid']; Quote Link to comment https://forums.phpfreaks.com/topic/196781-count-it/#findComment-1033047 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.