Jump to content

Recommended Posts

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

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

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

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.