[pmwiki-users] SelectQuery question
Ben Stallings
ben at interdependentweb.com
Thu Oct 9 10:51:01 CDT 2008
Dave Brockman wrote,
> I installed SelectQuery and it works fine. Thank you very much! But, I
> was wondering if there is a way to use page variables in the query? I'm
> just starting with MySQL and know very little about it. I didn't make
> the database I am accessing. Here's what I would like to do:
>
> (:selectquery columns="first_name,last_name,YEAR(death_date)"
> tables=actor where="MONTH(death_date) = $CurrentMonth AND
> DAYOFMONTH(death_date) = $CurrentDay":)
>
> This works fine if $CurrentMonth and $CurrentDay are replaced with
> numbers. I added those page variables to config.php per the
> MoreCustomPageVariables recipe. They work in {normal} usage.
>
> Is there a way to make this work? Thanks in advance!
Hi, Dave! I'm glad SelectQuery is working for you!
I'm afraid you've made it more complicated than it needs to be --
MySQL's date functions default to the current time when given no value,
so as long as you only want to run this query for the *current* month
and date, you'll be better off writing the query like this:
(:selectquery columns="first_name,last_name,YEAR(death_date)"
tables=actor where="MONTH(death_date) = MONTH() AND
DAYOFMONTH(death_date) = DAYOFMONTH()":)
If you want to use values *other* than the current month and date, you
need to put the page variables' names in {braces}, like so:
(:selectquery columns="first_name,last_name,YEAR(death_date)"
tables=actor where="MONTH(death_date) = {$TargetMonth} AND
DAYOFMONTH(death_date) = {$TargetDay}":)
I hope this helps!
Ben Stallings
Interdependent Web
More information about the pmwiki-users
mailing list