Jump to content

Archived

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

fogofogo

php/sql problem

Recommended Posts

Hi folks,

I have a form that submits a date in this format : June 2006, and I am trying to use it to select records in a mysql database, that stores the date in this format: 2006-06-01.

So I must change June 2006 into 2006-06-01 and then feed it into the feed the date into the SQL statement - right?? This is the part I am stuck on.

some thing like this?

$formattedDate = date("F Y", strtotime($month));

my code so far (which is probably way off), looks like this...

[code]<?php

// print out the month that has been choosen

$month = $_POST['date'];
echo $month;

//$formattedDate = date("F Y", strtotime($month));

...
database stuff
...

$query = mysql_query("SELECT DISTINCT ddate, DATE_FORMAT(ddate, '%Y %M')  ID FROM pokercredit");

// print out the records

while ($row = mysql_fetch_array($query)){
echo "$row[ID] $row[dfrom] $row[damount]<br>";     // name class and mark will be printed with one line break at the end
}

?>[/code]


I'm obviously way off but any advice would be great, as I'm totally stuck on this.

Thanks all

J

Share this post


Link to post
Share on other sites
fixed it - if anyone would like to see the code:

[code]<?php
// print out the month that has been choosen
$month = $_POST['date'];
echo $month;

include("db.php");

// select the ddate
//echo "SELECT * FROM  pokercredit WHERE DATE_FORMAT(ddate, '%Y %M')='.$month;

$query = mysql_query("SELECT * FROM  pokercredit WHERE DATE_FORMAT(ddate, '%Y %M')='".$month."'");

// print out the records
while ($row = mysql_fetch_array($query)){
echo "$row[ID] $row[dfrom] $row[damount]<br>";     // name class and mark will be printed with one line break at the end
}

?>[/code]

it might be messy, but it works!

Share this post


Link to post
Share on other sites

×

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.