Re: [PHP] Clean Up the sand box time

This is a discussion on Re: [PHP] Clean Up the sand box time within the PHP General forums, part of the PHP Programming Forums category; On Friday 22 Aug 2003 10:26 pm, John Taylor-Johnston wrote: > This is my favourite question. Can I ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-23-2003
Nicholas Robinson
 
Posts: n/a
Default Re: [PHP] Clean Up the sand box time

On Friday 22 Aug 2003 10:26 pm, John Taylor-Johnston wrote:
> This is my favourite question. Can I clean up my 'if then' statements a
> tad? Must be a cleaner way?
> Still learning, still having fun :)
> Thanks,
> John
>
> $news = mysql_query($sql) or die(print
> "document.write(\"".mysql_error()."\");");
>
> $found = 0;
> while ($mydata = mysql_fetch_object($news))
> {
> if($getaddr == $mydata->IPAddress)
> {
> $found = 1;
> }
> }
>
> if ($found > 0)
> {
> echo "document.write(\"$getaddr already visited. \");";
> }else{
> echo "document.write(\"insert $getaddr into $table. \");";
> }


Not sure at exactly what level you're looking to improve it!

Could you improve the query so you didn't have to search through all the
records? i. e. add in '..where IPAddress = $getaddr" That way you coulddo
away with the while loop altogether.

If you can't then why not break out of the while as soon as you've found the
IPaddress you're looking for - i.e.

if ( $found = $getaddr == $mydata->IPAddress ) break;

And finally, if you were really having a downer on if statements you could use
the ternary operator form as in:

document.write( ( $found ) ? "...already vistied" : "insert..." );

Whatever you use, I think Robert's layout not only shows elegance and panache
but also makes it much easier to read.

HTH

Nick

PS: IP addresses are a notoriously bad way of checking to see if someone's
visited your site.


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:02 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0