Jump to content

sql count help please!


SillOega

Recommended Posts

Hey!

Im pretty new to PHP but trying to learn.  8)

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

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.