SillOega Posted August 18, 2011 Share Posted August 18, 2011 Hey! Im pretty new to PHP but trying to learn. I have search the web and cant find any help for my problem. I have a counter on my page which saves ip, date and time (and ofcourse an id). I have this code right now: <? $länk = @mysql_connect("host","user","pass") or die("Kunde inte ansluta!"); $databas = mysql_select_db("database"); $sql = mysql_query("SELECT COUNT(*) FROM logg WHERE tid > " . date("Y-m-d")); $day_records = mysql_num_rows($sql); echo $day_records; mysql_close($länk); ?> This code is supposed to pick out all hits from today. If there is 20 records or 0 records, it still gives me 1. And this code is for picking up visitors from yesterday: <? $länk = @mysql_connect("host","user","pass") or die("Kunde inte ansluta!"); $databas = mysql_select_db("mjmotor"); $sql = mysql_query("SELECT COUNT(*) FROM logg WHERE tid BETWEEN " .date("Y-m-d", strtotime("-1 days")). " AND " .date("Y-m-d")); $yesterday_records = mysql_num_rows($sql); echo $yesterday_records; mysql_close($länk); ?> Same here i always get the value 1. Database field "tid" is in YYYY-MM-DD HH:MM:SS As i said im new to PHP and hope someone could help me Link to comment https://forums.phpfreaks.com/topic/245113-sql-count-help-please/ Share on other sites More sharing options...
doddsey_65 Posted August 18, 2011 Share Posted August 18, 2011 $row = mysql_fetch_assoc($sql); $day_records = $row['COUNT(*)']; or you could do: $sql = mysql_query("SELECT * FROM logg WHERE tid > " . date("Y-m-d")); $day_records = mysql_num_rows($sql); Link to comment https://forums.phpfreaks.com/topic/245113-sql-count-help-please/#findComment-1259004 Share on other sites More sharing options...
SillOega Posted August 18, 2011 Author Share Posted August 18, 2011 ty for quick answer.. if i do the first solution i get no result at all.. if i do the second i get the total amount. Could the problem be that its YYYY:MM:DD hh:mm:ss ? if i try this: $sql = mysql_query("SELECT * FROM logg WHERE tid > " . date("Y-m-d")). " 00:00:00"; i get nothing... Link to comment https://forums.phpfreaks.com/topic/245113-sql-count-help-please/#findComment-1259009 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.