Jump to content

get month from database


mraza

Recommended Posts

Where is your code to display the results. The problem may be in that code. Also, do you really want to show all records from a specific month or do you really want to show the records from a specific MONTH & YEAR? That query above would get records from March of any year.

thanks for reply sir,

here is my code

$sql= $dbc->dbRunSql("select * from points WHERE MONTH(date) = '03' " );
$records = mysql_fetch_assoc($sql);
print_r($records);

i am doing a print_r and i see only one row

Array
(
    [id] => 1
    [userid] => 2
    [points] => 1000
    [date] => 2011-03-05
    [month] => 0
)

only above shows but i have more records in 03 Month.

Edit: i wants to show record from a month but like to know for year too. thanks

Well, I just tested it several different ways and it worked for me.

SELECT * FROM `scan_jobs` WHERE MONTH(`started`) = 3
SELECT * FROM `scan_jobs` WHERE MONTH(`started`) = '03'
SELECT * FROM `scan_jobs` WHERE MONTH(`started`) = "03"

 

The problem must be in your data. Is the field set as a date field and did you validate that the values you expect for those records is correct? if you have a page where you are entering the records you might have a bug that is not saving the dates correctly.

 

EDIT: Scratch that

 

You still need to run a mysql_fetch for EACH record. The first one will only get the first record!!!

 

$sql= $dbc->dbRunSql("select * from points WHERE MONTH(date) = '03' " );
while($record = mysql_fetch_assoc($sql))
{
    print_r($record);
}

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.