Why is this in a spin and Timing Out?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Why is this in a spin and Timing Out?

Post by simonmlewis »

This is checking on the product ID from a string (344|232|112... for ex) and then to see if the Title of that code is "grout", and then if it is, it produces the dropdown list.

It just stopped the timeout but went into a complete spin at line 228, which is
" while ($rowac = mysql_fetch_object($resultancscheck))".

Code: Select all

if ($row->ancillaryoverride == "yes")
{
  $string = "$row->ancillaries";
  $token = strtok($string,"|");
  while($token)
  {
  $resultanccheck = mysql_query ("SELECT title, photoprimary, romancode1, romancode2, romancode3, romancode4, size1, size2, size3, size4 FROM products WHERE id = '$token'")or die(mysql_error()); 
    while ($rowac = mysql_fetch_object($resultancscheck))
    {    
    if (preg_match("/grout/i", "$rowac->title")) 
      { 
      echo "<tr><td><img src='/images/productphotos/small/$rowac->photoprimary' /> </td><td>$rowac->title<br/>Please choose your Grout:<br/>
      <select name='romancode1'>";
      if ($rowac->size1 != '') { echo "<option name='romancode1' value='$rowac->romancode1'>$rowac->size1</option>";}
      if ($rowac->size2 != '') { echo "<option name='romancode2' value='$rowac->romancode2'>$rowac->size2</option>";}
      if ($rowac->size3 != '') { echo "<option name='romancode3' value='$rowac->romancode3'>$rowac->size3</option>";}
      if ($rowac->size4 != '') { echo "<option name='romancode4' value='$rowac->romancode4'>$rowac->size4</option>";}
      echo "</select></td></tr>";
      }
    }
  }
  $token = strtok("|");
}
// end of ancillaryoverride question
echo "</table>";
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Why is this in a spin and Timing Out?

Post by social_experiment »

Code: Select all

<?php
while ($rowac = mysql_fetch_object($resultancscheck))
?>
the variable passed to mysql_fetch_object is called $resultancscheck while the one containing the query is $resultanccheck (missing an 's' between the two 'c' s)
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply