A very basic PHP question
am 25.04.2008 10:58:22 von Nasreen Laghari
--0-1052703182-1209113902=:72688
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Hi,
I have some confusion with Variables scope. I searched but couldn't figure it out :(
The question is:
one variable which changes according to if... else statment, how do you change the value of that variable?
Actually $query is changing on $type variable so I tried doing using if.. else statment. Please clarify me.
function select_entries_quick ($offset=0,$location,$type)
{
global $limit;
$query;
$date = date("d/m/y");
if (empty($offset)) { $offset = 0; }
if($type=="today")
{
$query = "SELECT * FROM gig where gig_Date= $date";
}
else if($type=="tomorrow")
{
$tomorrow = mktime(0, 0, 0, date("m") , date("d")+1, date("Y"));
$query = "SELECT * FROM gig where gig_Date= $tomorrow";
}
else if($type=="week")
{
$week = mktime(0, 0, 0, date("m") , date("d")+6, date("Y"));
$query = "SELECT * FROM gig WHERE g.gig_Date <= ".$date." OR g.gig_Date >=".$week.";
}
$result = safe_query($query);
return $result;
}
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
--0-1052703182-1209113902=:72688--
Re: A very basic PHP question
am 25.04.2008 14:24:15 von Peter Westergaard
I'm not sure this has to do with Variable Scope. (Scope has to do with
when you can or can't reference a variable ... for example, that you may
have defined in a different function than the currently-running code).
I don't actually understand your question that well, either. Can you
elaborate? Which value are you asking how to change?
As I understand it, your code basically does the following:
[Assumes $offset and $type are passed in from whatever code calls this
function]
Defaults $offset to 0 if it wasn't defined.
Generates one of three different queries based on the passed-in "type":
- "today" generates a SQL statement using today's date.
- "tomorrow" generates a SQL statement using tomorrow's date.
- "week" generates a SQL statement using the next week (or rather, it
tries to, but the SQL statement will in fact return every single gig in
the system OTHER than the ones in the next 5 days).
The SQL Statement is cleaned using a safe_query function, and returned
to the code that called this function.
So if you're asking how to change the value of "type", you just go to
the code elsewhere in your application that calls
"select_entries_quick()" and change the third parameter.
If you have a different question, can you elaborate?
-P
Nasreen Laghari wrote:
> Hi,
>
> I have some confusion with Variables scope. I searched but couldn't figure it out :(
>
> The question is:
> one variable which changes according to if... else statment, how do you change the value of that variable?
>
> Actually $query is changing on $type variable so I tried doing using if.. else statment. Please clarify me.
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php