Jump to content

Count number of days in db by date listed...


siafulinux

Recommended Posts

Okay, here's a quick question. I am somewhat new to PHP but have created an application but am stuck at how to do something.

 

I have a table with entries and a date stamp in mm/dd/yyyy format. I want to count how many days there were but only counting 1 day if there are say 20 entries for one specific day! In other words lets say there are:

 

10 entries for 10/05/2007

and

5 entries for 10/10/2007

The count should result as 2 days.

 

I have tried while loops but they keep causing the browser to not load the page.

Here is an example of what I've tried:

 

// GET THE NUMBER OF DAYS FOR ENTRIES

$query = "SELECT (date) AS date FROM data";

$result = mysql_query($query) or die(mysql_error());

 

// EXECUTE THE ABOVE QUERY

$number = 0;

while ($row = mysql_fetch_array($result)){

while ($row['date'] == $row['date']) {    // Also tried    if ($row['date'] == $row['date']) {

$number = $number + 1;

echo $number;

}

}

 

 

 

Can anyone help with this?

 

Much appreciated.

Siafu

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.