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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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