RE: [PHP] SQL in Function
| From: | Mark Roedel | Date: | Mon, 26 Nov 2001 22:49:48 +0000 |
| Subject: | RE: [PHP] SQL in Function | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-75741@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Oosten, Sjoerd van [mailto:SvOosten@esites.nl]
> Sent: Thursday, November 22, 2001 2:01 AM
> To: 'php-general@lists.php.net'
> Subject: [PHP] SQL in Function
>
>
> function Activeyesno($month,$day,$year,$Project_id){
> $dayactief = mktime(0, 0, 0, $month, $day, $year);
> $daytemp = date("Y-m-d", $dayactief);
> $resultactive = mysql_query("SELECT * FROM EIAProjecten WHERE
> ((Project_begindatum >= '$daytemp' AND Project_id = '$Project_id') OR
> (Project_einddatum <= '$daytemp' AND Project_id =
'$Project_id'))",$db);
>
> $num_rows = mysql_num_rows($resultactive);
> if ($num_rows == '1'){
> return "red"; }
> }
>
> 1. Is it possible to make a sql connection in my function
Yes.
> 2. did i do something wrong?
Yes.
The thing you have to remember is that your database link identifiers,
etc., follow the same rules of scope as any other variable (and thus,
need to either be passed into your function as parameters or declared as
global).
Specifically, in your case, the $db variable referenced in your
mysql_query() call doesn't appear to have a value that's local to this
function.
---
Mark Roedel | "Blessed is he who has learned to laugh
Systems Programmer | at himself, for he shall never cease
LeTourneau University | to be entertained."
Longview, Texas, USA | -- John Powell