Hi eveyone this code is correct or not ?? because im gettin this error
not:i didnt write just copy paste and it works there
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\Page\index.php on line 7
<?php
$con=mysql_connect("localhost","root","") or die ("Mysql Error");
$db=mysql_select_db("ziyaretci") or die ("Connection Error");
$rec_count=mysql_fetch_array(mysql_query("SELECT count (*) from memberinfo"));
echo $rec_count;
?>
Row count
Moderator: General Moderators
Re: Row count
You have the wrong function. It should be:
Code: Select all
<?php
$con=mysql_connect("localhost","root","") or die ("Mysql Error");
$db=mysql_select_db("ziyaretci") or die ("Connection Error");
$rec_count=mysql_num_rows(mysql_query("SELECT count (*) from memberinfo"));
echo $rec_count;
?>
Re: Row count
hi my friend plase someone check this link all the videos in this site are wrong or am i blind or an idiot????
http://www.seyretogren.com/video/php-de ... apmak.html
http://www.seyretogren.com/video/php-de ... apmak.html
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Row count
The way he used the functions were correct, just not recommended. The issue is when mysql_query() fails, it will return a boolean false, which is obviously not the resource mysql_fetch_assoc() is expecting.
Firstly, you should generally always have some form of error checking on your queries. The most common being
You'll also notice I added an alias to more easily reference the aggregate function column.
Firstly, you should generally always have some form of error checking on your queries. The most common being
Code: Select all
$result = mysql_query("SELECT count (*) AS `count` from memberinfo") or die(mysql_error());
$rec_count = mysql_fetch_array($result);