Re: [PHP-DB] What's wrong with my function? :(
Tx. Yep I have read it now and understood it better than the first time I read this part of the manual (it's amazing how things make more sense when you can apply them to what you are doing). Jesse Goerz [EMAIL PROTECTED] wrote in message 0110301727.19453@reign">news:0110301727.19453@reign... On Tuesday 30 October 2001 15:49, TorrentUK wrote: Please could some take a look at this code and tell me why when I take my IF statements out of the function and put in them in the same place where I call the function from they work, but as soon as I replace them with the function name they don't? Appreciate any help. torrent Here's the code... Your variable is not in scope. Either pass your variable as a reference in the function definition: function RatingFilter ($sql) { ... } or use the global keyword to bring your variable into scope: function RatingFilter () { global $sql; if ($br) {$sql.= and beg_rate = '2';} ... } And follow the advice of Charles and read up on it so you know how they are different. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] What's wrong with my function? :(
Please could some take a look at this code and tell me why when I take my IF statements out of the function and put in them in the same place where I call the function from they work, but as soon as I replace them with the function name they don't? Appreciate any help. torrent Here's the code... // Define the rating's filter ?php function RatingFilter () { if ($br) {$sql.= and beg_rate = '2';} if ($ir) {$sql.= and int_rate = '2';} if ($ar) {$sql.= and adv_rate = '2';} if ($sr) {$sql.= and sbd_rate = '2';} } ? if ($search) { include ('logon-inc.php'); $sql = SELECT rsrt_name, ctry_name FROM resort_tbl WHERE ctry_name='$country[0]'; RatingFilter(); --- If I put 'if' statement here instead it works for ($n=1; count($country) $n; $n++){ $sql.= or ctry_name='$country[$n]'; RatingFilter(); -- Or here } . . . . } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] What's wrong with my function? :(
On Tue, 30 Oct 2001, TorrentUK wrote: SNIP you either need to pass the variables to the function or use global variables in the function see http://www.php.net/manual/en/language.variables.scope.php Here's the code... // Define the rating's filter ?php function RatingFilter () { if ($br) {$sql.= and beg_rate = '2';} if ($ir) {$sql.= and int_rate = '2';} if ($ar) {$sql.= and adv_rate = '2';} if ($sr) {$sql.= and sbd_rate = '2';} } ? if ($search) { include ('logon-inc.php'); $sql = SELECT rsrt_name, ctry_name FROM resort_tbl WHERE ctry_name='$country[0]'; RatingFilter(); --- If I put 'if' statement here instead it works for ($n=1; count($country) $n; $n++){ $sql.= or ctry_name='$country[$n]'; RatingFilter(); -- Or here } . . . . } -- Charles F. McKnight IRC: sokudo | Doubt is not a pleasant condition, but [EMAIL PROTECTED] ICQ: 2794793 | certainty is absurd. [EMAIL PROTECTED] PGP: 0x20A5BCE5 | - Voltaire [ http://chucksays.mywebsitesucks.com ]- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] What's wrong with my function? :(
I'm new to PHP but one thing I think might be happening is that maybe the changes aren't being made to a global (I'm a Java programmer) $sql so they aren't being kept. Does it actually break or is it not appending the additional string? I'd try printing out the $sql and see what you're getting - possibly at different stages of the program - like before and after you call your function. Good luck! -Natalie -Original Message- From: TorrentUK [SMTP:[EMAIL PROTECTED]] Sent: Tuesday, October 30, 2001 3:50 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] What's wrong with my function? :( Please could some take a look at this code and tell me why when I take my IF statements out of the function and put in them in the same place where I call the function from they work, but as soon as I replace them with the function name they don't? Appreciate any help. torrent Here's the code... // Define the rating's filter ?php function RatingFilter () { if ($br) {$sql.= and beg_rate = '2';} if ($ir) {$sql.= and int_rate = '2';} if ($ar) {$sql.= and adv_rate = '2';} if ($sr) {$sql.= and sbd_rate = '2';} } ? if ($search) { include ('logon-inc.php'); $sql = SELECT rsrt_name, ctry_name FROM resort_tbl WHERE ctry_name='$country[0]'; RatingFilter(); --- If I put 'if' statement here instead it works for ($n=1; count($country) $n; $n++){ $sql.= or ctry_name='$country[$n]'; RatingFilter(); -- Or here } . . . . } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] What's wrong with my function? :(
Yep, that'll be it. Thanks for the help. :) torrent Charles F. McKnight [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... On Tue, 30 Oct 2001, TorrentUK wrote: SNIP you either need to pass the variables to the function or use global variables in the function see http://www.php.net/manual/en/language.variables.scope.php Here's the code... // Define the rating's filter ?php function RatingFilter () { if ($br) {$sql.= and beg_rate = '2';} if ($ir) {$sql.= and int_rate = '2';} if ($ar) {$sql.= and adv_rate = '2';} if ($sr) {$sql.= and sbd_rate = '2';} } ? if ($search) { include ('logon-inc.php'); $sql = SELECT rsrt_name, ctry_name FROM resort_tbl WHERE ctry_name='$country[0]'; RatingFilter(); --- If I put 'if' statement here instead it works for ($n=1; count($country) $n; $n++){ $sql.= or ctry_name='$country[$n]'; RatingFilter(); -- Or here } . . . . } -- Charles F. McKnight IRC: sokudo | Doubt is not a pleasant condition, but [EMAIL PROTECTED] ICQ: 2794793 | certainty is absurd. [EMAIL PROTECTED] PGP: 0x20A5BCE5 | - Voltaire [ http://chucksays.mywebsitesucks.com ]- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]