Jump to content

Archived

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

spooooky

date comparision --- wrong file type / format?

Recommended Posts

Hi folks!

 

I´m desperate. I\'m trying to compare dates from a user input (drop down menu) with those of a mysql DB in \"date\" format. I force the user input to be the same format (YYYY-MM-DD) as those in my DB.

I tried all kinds of combinations of \"<>=\", sometimes i get all results, sometimes none and sometimes only those that dont even have a date (then 0000-00-00).

What am I doing wrong?!

 

thx in advance! your site did already help me out often enough!

 




<?php



$filter=$_POST[\'checkboxes\'];         // Zuweisung der Auswahl aus "filtercheck_DHR.php" to array

$andtime=$_POST[\'zeit\'];



if ($andtime) {

 $D=$_POST[\'tag\'];  // format of \'tag\': XX

 $M=$_POST[\'monat\']; // format of \'monat\': XX

 $Y=$_POST[\'jahr\']; // format of \'jahr\': XXXX

 $help="$Y-$M-$D";

 $date="Von <= $help <= Bis"; // sql query part in var $date 

       	// (for timecheck: $help should lie in between start and end date of matching offers) 

     	// "Von" and "Bis" in \'date\' file type  

}  



$count=count($_POST[\'checkboxes\']);

switch($count) {  // sql query part for var $cat

case 1: $cat="Angebotskategorie=\'$filter[0]\'"; break;

case 2: $cat="Angebotskategorie=\'$filter[0]\' OR Angebotskategorie=\'$filter[1]\'"; break;

case 3: $cat="Angebotskategorie=\'$filter[0]\' OR Angebotskategorie=\'$filter[1]\' OR Angebotskategorie=\'$filter[2]\'"; break;

case 4: ...





}



$select="SELECT * FROM Angebot WHERE ";

$order="ORDER BY Angebotskategorie"; 



if ($andtime) { // 

$sql="$select ($date) AND ($cat)"; }

else {

 $sql="$select $cat $order"; }



echo ($sql);



$link_id=mysql_connect("localhost","....") or die("keine Verbindung");  // DB connection

mysql_select_db("0251_reiseshop") or die("Datenbankauswahl nicht möglich");	

$result=mysql_query($sql, $link_id);  // SQL query



if ($result) {      	// output results

$number=mysql_num_rows($result);

echo "Ihre Auswahl liefert $number Ergebnis(se)";

echo "<TABLE BORDER=1>";

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

 echo "<TR><TD>";

 echo implode("<TD>",$row);

 echo "</TR>";

 }

 echo "</TABLE>";

} else {

 echo "<P>".mysql_error($link_id);

}

mysql_close($link_id);     // DB disconnection



?>



Share this post


Link to post
Share on other sites

What are u trying to do

 

are u trying to compare two dates and fine the result??

 

can u be a little clear!

Share this post


Link to post
Share on other sites

it´s supposed to be kind of a search function. u select different categories and a date and then u get several results. in my case those results are mostly events or sth. so they have a start date and an end date.

my search function works perfect without date selected.

but anyway the user should be able to select also by date. so he chooses a date from my drop down menu and only those results should be returned, that match the categories AND the selected user date must be in between the start and end date of those results. i try to handle this with the sql query:

 

SELECT * FROM Angebot WHERE Von <= $help <= Bis AND Angebotskategorie=\'$filter[0]\' OR Angebotskategorie=\'$filter[1]\' OR ...

 

where \"Angebot\" is the event table, \"Von\" the start and \"Bis\" the end date

$help is the date selected by user in this format: YYYY-MM-DD

Share this post


Link to post
Share on other sites

so u want to display records based on (from) ( to)

 

what have u defined the filed which has the date

 

is that timestamp or int or varchar??

 

u can use

 

select * from table_name where date_filed between (start_date) 20021129 and 20021211(enddate)

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.