Re: How come this will echo No or nothing?
| From: | Matthew K. Gold | Date: | Sun, 14 Jul 2002 13:21:08 +0000 |
| Subject: | Re: How come this will echo No or nothing? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-107601@lists.php.net to get a copy of this message | ||
this is from the O'Reilly _Programming PHP_ (Rasmus Lerdorf & Kevin Tatroe):
"Because echo is not a true function, you can't use it as part of a larger
expression:
// parse error
if (echo("test)) {
echo("it worked!";
}
Such errors are easily remedied, though, by using the print() or printf()
functions."
p. 76
Here's how I solved a similar problem:
if ( $foo != '' ) print (" yes");
and then just add the else statement...
best,
Matt
----- Original Message -----
From: César Aracena <icaam@icaam.com.ar>
To: 'JJ Harrison' <webmaster@tececo.com>; <php-general@lists.php.net>
Sent: Sunday, July 14, 2002 5:42 AM
Subject: RE: [PHP] How come this will echo No or nothing?
> I've come up with this before and solved it like this (guess it'll
> work):
>
> if($row['plevel'] == '0'){
> echo 'No';
> } else if($row['plevel'] != '0'){
> echo 'Yes';
> }
>
> Notice the *ELSE IF* instead of a simple else statement. Try it.
>
> C.
>
> > -----Original Message-----
> > From: JJ Harrison [mailto:webmaster@tececo.com]
> > Sent: Saturday, July 13, 2002 1:01 AM
> > To: php-general@lists.php.net
> > Subject: [PHP] How come this will echo No or nothing?
> >
> > here is the portion of the script:
> >
> > if($row['plevel'] == '0'){
> > echo 'No';
> > } else {
> > echo 'Yes';
> > }
> >
> > here is my table structure dump:
> >
> > #
> > # Table structure for table
docs
> > #
> >
> > CREATE TABLE docs (
> > id int(11) unsigned NOT NULL auto_increment,
> > name varchar(200) NOT NULL default '',
> > note varchar(200) NOT NULL default '',
> > author varchar(200) NOT NULL default '',
> > path varchar(200) NOT NULL default '',
> > plevel tinyint(3) NOT NULL default '0',
> > type char(3) NOT NULL default '',
> > cat tinyint(3) NOT NULL default '0',
> > file_size int(11) unsigned NOT NULL default '0',
> > date int(11) unsigned NOT NULL default '0',
> > PRIMARY KEY (id)
> > ) TYPE=MyISAM;
> >
> > the row plevel is either 0 or 1.
> >
> > why won't this script echo Yes?
> >
> > The reason that the plevel is set in numbers is because I may add
> higher
> > ones later.
> >
> > --
> > JJ Harrison
> > webmaster@tececo.com
> > www.tececo.com
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php