kickstart Posted March 20, 2009 Share Posted March 20, 2009 Hi If it returns nothing then it will not get into the while loop. Try this:- $Mquery = mysql_query("SELECT * FROM products WHERE id!='' $sequery limit 1"); if($getproductlink = mysql_fetch_array($Mquery)) { $intable = "".$getproductlink['sku'].""; if(isset($intable)) { print "".$intable." - <b>Matched To</b> - ".$tempsku.""; } else { print "<b>No Match Found For:</b> ".$tempsku.""; } mysql_query("UPDATE temp SET msku='".$getproductlink['sku']."' category='".$getproductlink['category']."' subcategory='".$getproductlink['subcategory']."' productgroup='".$getproductlink['productgroup']."' WHERE sku='".$tempsku."'"); $chk = mysql_fetch_array(mysql_query("SELECT * FROM skumatch WHERE temp_sku='".$tempsku."'")); $old = $chk['temp_sku']; if(!$old) { mysql_query("INSERT INTO skumatch (`main_sku`, `temp_sku`) VALUES ('".$intable."', '".$tempsku."')"); } } else { print "<b>No Match Found For:</b> ".$tempsku.""; } All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/150281-solved-else-not-working/page/2/#findComment-789360 Share on other sites More sharing options...
PHPNewbie55 Posted March 20, 2009 Author Share Posted March 20, 2009 I'll try that... It seems that the echo var_dump($intable); is returning the string(0) "" Quote Link to comment https://forums.phpfreaks.com/topic/150281-solved-else-not-working/page/2/#findComment-789366 Share on other sites More sharing options...
PHPNewbie55 Posted March 20, 2009 Author Share Posted March 20, 2009 That WORKS... THANKS!!!!!!!!! Now I just have to figure out just understand why... I added a counter earlier that should have accomplished the same thing... if($counter=0).. But THANK YOU!!!!!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/150281-solved-else-not-working/page/2/#findComment-789374 Share on other sites More sharing options...
PHPNewbie55 Posted March 20, 2009 Author Share Posted March 20, 2009 kickstart - THANK YOU!! That was awesome.... Very much appreciated..!!!! Quote Link to comment https://forums.phpfreaks.com/topic/150281-solved-else-not-working/page/2/#findComment-789381 Share on other sites More sharing options...
phant0m Posted March 20, 2009 Share Posted March 20, 2009 if($counter=0) this will always evaluate to false, because: this is an assignment, and every assignment itself evalutaes always the value which is being assigned(0) Because 0 is assigned to $counter, the entire assignment represents 0, which evaluates false. To compare, you have to use == Note: if you put the immediate first, (0 = $counter) it will result in a PHP error 0 == $counter and $counter == 0 however, are equivalent Quote Link to comment https://forums.phpfreaks.com/topic/150281-solved-else-not-working/page/2/#findComment-789382 Share on other sites More sharing options...
kickstart Posted March 20, 2009 Share Posted March 20, 2009 Hi Way it works is that mysql_query executes the query and sorts out the results. That might be 1 row, 10 rows or no rows at all, although you have specified a max of 1 record in the sql. mysql_fetch_array brings back a row. Doing while($getproductlink = mysql_fetch_array($Mquery)) is doing a loop, bringing back each row and assigning it to $getproductlink. When there are no more rows left it drops out of the while loop. If there were no rows at all then it never goes into the loop. Hence changing it to an if processes the possible 1 row you were expecting, and if no rows are returned it drops into the else. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/150281-solved-else-not-working/page/2/#findComment-789383 Share on other sites More sharing options...
PHPNewbie55 Posted March 20, 2009 Author Share Posted March 20, 2009 Keith, Yes I see that now... I usually try to follow the logic... this time I didn't back up enough because I "thought" it was OK.. LOL Guess no matter if I think it is OK or not... if PHP/MySQL doesn't.. then I need to follow the logic back further... Sometimes you get the googly script eyes that won't allow you to see things clearly.. like beer goggles! Quote Link to comment https://forums.phpfreaks.com/topic/150281-solved-else-not-working/page/2/#findComment-789954 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.