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
How to put variable in a function and a function in sql
Old 02-12-2008, 07:04 PM How to put variable in a function and a function in sql
Experienced Talker

Posts: 36
Trades: 0
Code:
<input type='text' name='en_ch_date' value='<? echo date(("Ymd"), strtotime("-3 days")); ?>'>
This correctly outputs 20080204 with today being 20080207.

I want to put a variable in for -3 which will change but currently has a value of 100. How do I go about putting a variable in this function?

Also how would you add the date() function in a sql query like the one below?

Code:
 VALUES ('$_POST[mach_id]','Engine Oil','date("Ymd")','$_POST[en_ch_hours]')";
nlassiter is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-12-2008, 07:07 PM Re: How to put variable in a function and a function in sql
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Look directly for the database time functions.
For mysql:
Code:
Here is an example that uses date functions. The following query
selects all rows with a date_col value from within the last 30 days:    

   mysql> SELECT something FROM tbl_name
    -> WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= date_col;
http://dev.mysql.com/doc/refman/5.0/...functions.html

Quote:
Also how would you add the date() function in a sql query like the one below?
Code:
VALUES ('$_POST[mach_id]','Engine Oil',date('.date("Ymd").'),'$_POST[en_ch_hours]')";
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 02-12-2008 at 07:09 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-13-2008, 10:21 AM Re: How to put variable in a function and a function in sql
Experienced Talker

Posts: 36
Trades: 0
Thank you for your help.

In the first situation, I just want to replace the -3 with a variable like:

<input type='text' name='en_ch_date' value='<? echo date(("Ymd"), strtotime("$number days")); ?>'>
How do I do this?
nlassiter is offline
Reply With Quote
View Public Profile
 
Old 02-13-2008, 10:53 AM Re: How to put variable in a function and a function in sql
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
exactly the way you just did, and by defining
PHP Code:
$number="-3"
before outputting this HTML
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to How to put variable in a function and a function in sql
 

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.19791 seconds with 12 queries