I would like to get the number of rows that satisfies the condition.
mysql_query("SELECT COUNT(*) FROM sid WHERE sid='".session_id()."'");
this one ignores the condition.
update:
$session = session_id();
$sql = "SELECT COUNT(*) as row_count FROM sid WHERE sid = '$session' ";
var_dump($r = mysql_query($sql));//resource(4) of type (mysql result) (1)
var_dump(mysql_fetch_assoc($r));
//array(1) { ["row_count"]=> string(1) "1" } - this result is OK(2)
(1) resource(4) – I thought that 4 was the count
(2) mysql_real_escape_string($_SESSION['id']); gives 0
note:
I have changed from mysql_num_rows to this type of getting count because I thought it will return immediately the count and I dont have to write more lines to get this basic data.
The correct way of doing this is:
The table name and the column name can be the same, but in your case they probably are not.
sidobviously stands for the field “session_id”, so you need to replace the firstsidafterFROMwith your tablename.