 |
|
|
04-18-2005, 01:05 PM
|
Having a code issue
|
Posts: 52
|
Hello,
I have a form to search form to search a database from one date to another. In the database the field is set to a VARCHAR not DATE and the date format I'm using is MM/DD/YYY.
The code I'm using is,
PHP Code:
} elseif ((isset($_SESSION['Date_Sub1'])) && (isset($_SESSION['Date_Sub2']))) {
$sql_query = "select * from accounts where between Gereral_Date = '" . $_SESSION['Date_Sub1'] . "' AND General_Date = '" . $_SESSION['Date_Sub2'] . "'";
I know it's not very good but the code is error free but it just does not produce any results. I'm looking to search for the dates between date 1 and date 2 on a form. I can convert to a DATE format in my database if I have to but I will need to change some PHP code to work with the new format of YYYY/MM/DD
HELP!!!!!!
|
|
|
|
04-18-2005, 01:28 PM
|
|
Posts: 339
|
Hi Merlin.
I am afraid that you won't be able to search between two dates unless you conver to the American YYYY/MM/DD.
If you do that you can search using sqls with great ease.
To convert your dates back for onscreen purposes, use this function
PHP Code:
function date_convert($date,$type)
{
$date_year = substr($date,0,4);
$date_month = substr($date,5,2);
$date_day = substr($date,8,2);
if($type == 1) $date=date("Y", mktime(0,0,0,$date_month,$date_day,$date_year)); // Returns the year
elseif($type == 2) $date=date("F", mktime(0,0,0,$date_month,$date_day,$date_year));// Returns the month
elseif($type == 3) $date=date("M", mktime(0,0,0,$date_month,$date_day,$date_year));// Returns the month abbreviated
elseif($type == 4) $date=date("m", mktime(0,0,0,$date_month,$date_day,$date_year));// Returns month as 01, 02 etc
elseif($type == 5) $date=date("n", mktime(0,0,0,$date_month,$date_day,$date_year));// Returns month as 1,2,3 etc.
elseif($type == 6) $date=date("l", mktime(0,0,0,$date_month,$date_day,$date_year));// Returns the day of the week
elseif($type == 7) $date=date("D", mktime(0,0,0,$date_month,$date_day,$date_year));// Returns the day of the week abbreviated
elseif($type == 8) $date=date("D, M jS, Y", mktime(0,0,0,$date_month,$date_day,$date_year));// Returns combo 8
elseif($type == 9) $date=date("F jS, Y", mktime(0,0,0,$date_month,$date_day,$date_year));// Returns combo 9
elseif($type == 10) $date=date("d/m/y", mktime(0,0,0,$date_month,$date_day,$date_year));// Returns combo 9
elseif($type == 11) $date=date("F Y", mktime(0,0,0,$date_month,$date_day,$date_year));// Returns combo 9
return $date;
}
|
|
|
|
04-18-2005, 01:29 PM
|
|
Posts: 297
|
.
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill
Please visit my sites: Please login or register to view this content. Registration is FREE | Please login or register to view this content. Registration is FREE
|
|
|
|
04-18-2005, 01:31 PM
|
|
Posts: 52
|
I'm going to convert now and give it a try, thanks i'll let you know
|
|
|
|
04-18-2005, 01:40 PM
|
|
Posts: 52
|
Hi,
Nope, I made the change in the database and physically changed the dates in the database into the proper format then performed the search again with the same results.
No Errors but now data returned either.
Can you suggest anything else?
|
|
|
|
04-18-2005, 01:55 PM
|
|
Posts: 339
|
Have you seen the general date has been spelled as "gereral" date?
|
|
|
|
04-18-2005, 02:00 PM
|
|
Posts: 52
|
Yes, I am an idiot but I made the change and still no results, Argh!
Here's the query I'm using, anything you can sugesst would be great.
PHP Code:
$sql_query = "select * from accounts where between General_Date = '" . $_SESSION['Date_Sub1'] . "' AND General_Date = '" . $_SESSION['Date_Sub2'] . "'";
Thanks in advance. 
|
|
|
|
04-18-2005, 04:58 PM
|
|
Posts: 3,189
|
Your query is not actually performing that search on any particular column. Try this...
PHP Code:
$sql_query = "SELECT * FROM accounts WHERE General_Date BETWEEN '" . $_SESSION['Date_Sub1'] . "' AND'" . $_SESSION['Date_Sub2'] . "'";
Also, make sure that those sessions variables do contain actual and valid values.
|
|
|
|
|
« Reply to Having a code issue
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|