mysql - How do I validate a PHP integer within a variable? -


i have integrated yelp reviews directory site each venue has yelp id returning number of reviews , overall score.

following successful mysql query venue details, output results of database formatted user. yelp element is:

while ($searchresults = mysql_fetch_array($sql_result)) {   if ($yelpid = $searchresults['yelpid']) {         require('yelp.php');         if ( $numreviews > 0 ) {             $yelp = '<img src="'.$ratingimg.'" border="0" /> read <a href="'.$url.'" target="_blank">'.$numreviews.' reviews</a> on <a href="http://www.tkqlhce.com/click-7842347-10756740-1314724701000" target="_blank"><img src="graphics/yelp_logo_50x25.png" border="0" /></a><br />';         } else {             $yelp = '';         }     } //end if ($yelpid = $searchresults['yelpid']) { } //end while ($searchresults = mysql_fetch_array($sql_result)) { 

the yelp.php file returns:

$yrating = $result->rating; $numreviews = $result->review_count; $ratingimg = $result->rating_img_url; $url = $result->url; 

if venue has yelp id , 1 or more reviews output displays correctly, if venue has no yelp id or 0 reviews displays yelp review number of previous venue.

i've checked $numreviews variable type , it's integer. far i've tried multiple variations of "if ( $numreviews > 0 )" statement such testing against >=1, !$numreviews etc., converting integer string , comparing against other strings. there no errors , printing of variables returned gives correct number of reviews each property venues having no id or no reviews returning nothing (as opposed zero). i've compared directly against $result->review_count same problem.

is there better way make comparison or better format of variable work correct result?

edit: statement if ($yelpid = $searchresults['yelpid']) { not operating should. identical other statements in file, validating row contents work correctly given variable, e.g. $fbid = $searchresults['fbid'] etc.
when changed require('yelp.php'); require_once('yelp.php'); of venue outputs changed showing first iterated result. looking through venues outputted, error occurs on first venue after successful result makes me think there pervasive piece of code in yelp.php file, causing if ($yelpid = $searchresults['yelpid']) { ignored until positive result found (a yelpid in db), i.e. each venue correctly displayed yelp number of reviews until blank venue encountered. preceding venues' number of reviews displayed , continues each blank venue until venue found yelpid when shows correct number again. error reoccurs on next venue output no yelpid , on.

sample erroneous output: (line 1 var_dump)
string(23) "bayview-hotel-bushmills"
bayview hotel
read 3 reviews on yelp

benedicts
read 3 reviews on yelp (note no var_dump output, link contains url bayview hotel entry above)

string(31) "bushmills-inn-hotel-bushmills-2"
bushmills inn hotel
read 7 reviews on yelp

i suspect new question rather clutter/confuse 1 further?

end of edit

note: i'm aware of need upgrade mysqli have thousands of lines of legacy code update. i'm working on functionality before reviewing code best practice.

since yelp.php sort of blackbox; best explanation behavior set's variables if finds match. updating code should fix that:

unset($yrating, $numreviews, $ratingimg, $url); require('yelp.php'); 

i noticed peculiar if-statement, realize that's assignment or copy/paste error? if want test (that's if for)

if ($yelpid == $searchresults['yelpid']) { 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -