Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-18-2005, 01:05 PM Having a code issue
merlin's Avatar
Skilled Talker

Posts: 52
Trades: 0
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!!!!!!
merlin is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-18-2005, 01:28 PM
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
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
    } 
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 04-18-2005, 01:29 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
.
__________________
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
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 04-18-2005, 01:31 PM
merlin's Avatar
Skilled Talker

Posts: 52
Trades: 0
I'm going to convert now and give it a try, thanks i'll let you know
merlin is offline
Reply With Quote
View Public Profile
 
Old 04-18-2005, 01:40 PM
merlin's Avatar
Skilled Talker

Posts: 52
Trades: 0
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?
merlin is offline
Reply With Quote
View Public Profile
 
Old 04-18-2005, 01:55 PM
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Have you seen the general date has been spelled as "gereral" date?
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 04-18-2005, 02:00 PM
merlin's Avatar
Skilled Talker

Posts: 52
Trades: 0
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.
merlin is offline
Reply With Quote
View Public Profile
 
Old 04-18-2005, 04:58 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
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.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Having a code issue
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.51830 seconds with 12 queries