Re: Re: while...if statements???
| From: | Chris Lee | Date: | Wed, 19 Dec 2001 15:23:48 +0000 |
| Subject: | Re: Re: while...if statements??? | ||
| References: | 1 | Groups: | php.db php.general |
| Request: | Send a blank email to php-db+get-15101@lists.php.net to get a copy of this message | ||
personal pref. Once I knew php and mysql better I wrote my own wrappers, I found using them easier.
But there is no reason why someone couldnt do fine without one. writing a set of wrappers allowed me
to better optimize my queries and write code faster without having to worry about everything else.
have you tried the PEAR db wrappers? PEAR came out after I wrote mine, therfore I never used them,
you?
Chris Lee
lee@mediawaveonline.com
----- Original Message -----
From: "matt stewart" <matt@netvirtua.com>
To: "'Chris Lee'" <lee@mediawaveonline.com>;
<php-general@lists.php.net>; <php-db@lists.php.net>
Sent: Wednesday, December 19, 2001 1:16 AM
Subject: RE: [PHP-DB] Re: while...if statements???
> and i always thought the best tactic was to go ugly early.
>
> seriously, this isn't really that ugly a solution, most textbooks tend to
> tell you to use this method to start with as its a bit simpler to understand
> for beginners - an if...else statement to see if an initial row is returned,
> then you can happily use a do...while on that first row, and it'll carry on
> outputting the following rows if there are any more.
>
> -----Original Message-----
> From: Chris Lee [mailto:lee@mediawaveonline.com]
> Sent: 18 December 2001 20:49
> To: php-general@lists.php.net; php-db@lists.php.net
> Subject: [PHP-DB] Re: while...if statements???
>
>
> because the while() statement works like this
>
> - do something while x is true. if x is not true dont do anything.
> - do something while conent is in the db. if there is no conent in the db
> dont do anything.
>
> your if() statement is never run if there is no content.
>
> $return = mysql_fetch_row($result);
> if ( isset($return['pet_name']) )
> do
> {
> echo $return['pet_name'] ."<br>";
> } while( $return = mysql_fetch_row($result) );
> else
> echo " No Pets <br>";
>
> its ugly but it works. I dont like ugly, so I wrote my own db wrappers.
>
> http://www.mediawaveonline.com/examples/
>
> foreach( $db->select_array('', 'petinfo', '') as $pos =>
> $val )
> echo $val['pet_name'] ."<br>";
> if ( !isset($val['pet_name']) )
> echo " No Pets <br>";
>
> I like that more. but whatever.
>
> --
>
> Chris Lee
> lee@mediawaveonline.com
>
>
>
> "Jay Fitzgerald" <jayfitz@bayou.com> wrote in message
> news:5.1.0.14.2.20011218135212.014b4f30@mail.bayou.com...
> > Does anyone know why this isn't working?? What I am trying to do is
> display
> > photos from a database based on each month. This part works fine when I
> set
> > it to the current month of December (today) as that is when I uploaded the
> > photos.
> >
> > However, when I manually set the date to a month that has no photos in it,
> > I want it to echo the No Animals string below....This is only working
> > half-way...meaning that it will display a blank page with nothing on it
> > instead of actually echoing the No Animals string....
> >
> > Can anyone please help?? Is there really a way to have a "while...if"
> > statement????
> >
> >
> >
> > ========<CODE>=========
> > <?
> > $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to
> > connect!");
> > $query = "SELECT petname, petDesc, petpicture FROM petinfo WHERE petmonth
> =
> > 'Apr'";
> > $result = mysql_db_query($database, $query, $connection) or die ("Error in
> > query: $query. " . mysql_error());
> >
> > while (list($pet_name, $pet_Desc, $pet_picture) =
> mysql_fetch_row($result))
> > {
> > if ($pet_picture == "")
> > {
> > echo "No Animals have been posted for $date at this moment. Please check
> > back soon.";
> > exit;
> > }
> >
> > else
> > {
> > echo "
> > <FONT FACE=\"Arial, Helvetica\"><B>Pet of the
> > month</B></FONT><BR>
> >
> > <BR>
> > <IMG
> >
>
> SRC=\"http://moss.bayou.com:8888/oppj/admin/animalcontrol/photos/$pet_pictur
> e\"
> > HEIGHT=150><BR>
> >
> > <BR>
> > <FONT FACE=\"Arial, Helvetica\" SIZE=\"-1\">$pet_Desc<BR>
> >
> > <BR>
> > To adopt $pet_name please visit the Ouachita Parish Animal Shelter.<BR>
> > The adoption fee is \$50.00 which includes Spade, Neutering and 7-N-1
> > Shot.<BR>
> >
> > <BR>
> > Sorry, we can not hold $pet_name for you (First come first serve
> > basis).</FONT>
> > <BR><BR>";
> > }
> > }
> > ?>
> > ========</CODE>=========
> >
> > Thanks,
> >
> >
> > Confus3d
> >
> >
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.307 / Virus Database: 168 - Release Date: 11/12/01
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.307 / Virus Database: 168 - Release Date: 11/12/01
>
>