Jump to content


Photo

php/sql problem


  • Please log in to reply
1 reply to this topic

#1 fogofogo

fogofogo
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 02 June 2006 - 11:09 AM

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

<?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
}

?>


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

Thanks all

J

#2 fogofogo

fogofogo
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 02 June 2006 - 01:32 PM

fixed it - if anyone would like to see the 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
}

?>

it might be messy, but it works!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users