Re: or { blah blah blah }
| From: | DL Neil | Date: | Sat, 10 Nov 2001 02:57:45 +0000 |
| Subject: | Re: or { blah blah blah } | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-14212@lists.php.net to get a copy of this message | ||
> Inside a function, I am reading data from MySQL. In case any of these calls
> fail I follow them with something like:
>
> or echo "Can't make query to database!";
>
> The problem is, I want to do more things than just this... and then I want to
> return out of the function rather than continuing to execute statements.
>
> However, the following doesn't work... I get a parsing error.. How can it be
> done?
>
> or
> {
> echo "Can't make query to database!";
> return;
> }
>
> .. other statements ..
>
> I could have it call another function to do more things, but then how would I
> have it return out of it's current function when done doing those things?
> This is a pretty disasterous inability, not recognizing code blocks.
Hi Matthew,
Please check out the manual for details on the ternary operator - then consider that vis-a-vis
"code blocks".
The 'traditional' alternative using 'code blocks' would be:
$check = databaseFn(...);
if ( $check )
// then clause = successful, proceed with process
// (opt) else clause = failure, note in log/on screen, set indicators as appropriate, return
// use NOT in the condition if makes the code easier to read
Regards,
=dn