Re: Coding Question
| From: | Al | Date: | Mon, 06 Dec 2004 19:50:12 +0000 |
| Subject: | Re: Coding Question | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-203641@lists.php.net to get a copy of this message | ||
Jason Wong wrote:
On Monday 06 December 2004 14:19, Rory Browne wrote:Essentially, I'm creating warning reports for my users, not code errors. The users can then email the warnings to our webmaster. Here's what I ended up with:If I'm not mistaken Al wanted to return something if the thing failed, without having to put it inside an if_block. I'm watching this with curiosity, because return is a language construct, and not a function, or anything that has a value.You can have: ... OR $error = "Oh dear"; But the say I see it, eventually, somewhere in your code you need to test for it. Essentially you're just moving the test somewhere else.
@$host_link= mysql_connect($host, $user, $pw) OR $values['msg']= $values['msg'] . "Could not connect to mySQL host "; if($host_link){ $db_link= mysql_select_db($db, $host_link) OR $values['msg']= $values['msg'] . "Could not connect to mySQL DB: $db"; } if($host_link AND $db_link){ $result = mysql_db_query($db,"select count(*) from $table") OR $values['msg']= $values['msg'] . "Could not connect to mySQL Table: $table"; } if($host_link AND $db_link AND $result){The calling page echoes $values['msg'] in nice red text.$values['num_records'] = ($result>0) ? mysql_result($result,0,0) : 0;}//end if return $values; //tech notes and db table stuff