Re: FW: Problem with if/elseif

From: Date: Mon, 11 Sep 2000 21:29:37 +0000
Subject: Re: FW: Problem with if/elseif
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-16240@lists.php.net to get a copy of this message
You have to use == when comparing. if($search == "Artist search") Otherwise you are just assigning 'Artist search' to $search, which will allways be True hence it never gets by the first IF since it is allways true. > > I think I'm misunderstanding how if/elseif works with PHP3. In the example > below only the if statement is executed, the elseif and else statements are > never reached. > > <?php $pg = pg_pconnect("dbname=collection host=myhost.domain.net > user=postgres"); > echo "$search "; > if ($search = "Artist search") { > echo "$search "; > $result=pg_exec($pg, "select * from titles where artist ~~ > '%$art%' order by artist;"); > } else if ($search = "Title search") { > echo "$search "; > $result=pg_exec($pg, "select * from titles where title ~~ > '%$titl%' order by title;"); > } else { > echo "Push a button"; > }; > ?> > > ============================================================= > > When $search="Artist search" and $art="Adult" I get the proper results: > > Artist search Artist search > > Key Artist Title For Sale? > 1 Adult Net, The Incense and Peppermints Y > 4 Adult Net, The Edie Y > > ============================================================= > > When $search="Title search" and $titl="Incense" I get all the records in my > database and the second echo "$search" reverts back to "Artist search": > > Title search Artist search > > Key Artist Title For Sale? > > 1 Adult Net, The Incense and Peppermints Y > 4 Adult Net, The Edie Y > 5 Alternative TV Welcome to the End of Fun Y > 6 Batfish Boys, The Swamp Liquor Y > 3 Creation Rebel-New Age Steppers Threat to Creation Y > 7 Ministry KEOANHXO > 2 New Age Steppers Action Battlefield Y > > =============================================================== > > Am I doing something glaringly wrong? How do I get the elseif statement to > execute given my $search variable? > > Thanks, Greg > > > Because e-mail can be altered electronically, > the integrity of this communication cannot be guaranteed. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#16240) next »