Jump to content

Help!


artistan

Recommended Posts

I'm trying to run another sql query withing a while loop fetching rows of another query.
But for some reason I'm only expecting 2 rows, but the while loop goes into a infinite loop when I insert the 2nd query.

[code]    $item_result = $sys_database->sql_query(
    "SELECT `product`.`name`, `product`.`description`, "
    ."`product`.`height`, `product`.`length`, `product`.`width`, `product`.`weight`, "
    ."`product`.`base_price`, `product`.`price_unit`, "
    ."`item`.`iid`, `item`.`product_no`, `item`.`count`, `item`.`retail_price`, `item`.`status` FROM "
    ."`".$sys_config["dbpref"]."mod_inventory_product` AS `product`, "
    ."`".$sys_config["dbpref"]."mod_inventory_item` AS `item` "
    ."WHERE `product`.`pid` = `item`.`pid` AND `product`.`cid` = '$gp_mc_cid'");
    $item_count = $sys_database->sql_numrows($item_result);
    if($item_count) {
    $item_color = 0;
      while($item_item = $sys_database->sql_fetchrow($result)) {

      /* Any Query I insert here SELECT, INSERT, SHOW PROCESSLIST will cause the while loop to not end.
          Otherwise, it works just fine. */
      $sys_database->sql_query("SHOW PROCESSLIST");


        if($item_color == 1) {
        $item_color = 0;
        $id = " id=\"dark\"";
        } else {
        $item_color = 1;
        $id = "";
        }
        echo "    <div class=\"item\"".$id.">\n"
            ."    <div class=\"selection\"><input type=\"checkbox\" name=\"iid[]\" value=\"".$item_item["iid"]."\" /></div>\n"   
            ."    <div class=\"pid\">".$item_item["iid"]."</div>\n"
            ."    <div class=\"status\">\n";
        echo "    </div>\n"
            ."    <div class=\"quantity\">\n"
            ."    ".$item_item["count"]
            ."    </div>\n"
            ."    <div class=\"price\">\n"
            .$sys_config["unit_currency"].$item_item["retail_price"];

        if($sys_user->p_allinfo) echo "/".$sys_config["unit_currency"].$item_item["base_price"]."";
        echo "    </div>\n"
            ."    <div class=\"name\">\n"
            ."      <strong>".$item_item["name"]."</strong> [".$item_item["product_no"]."]<br />\n";
        $length = 50;
        $trailing = "...";
        $length-= strlen($trailing);
        if (strlen(stripslashes($item_item["description"])) > $length) {
        $item_description = substr(stripslashes($item_item["description"]),0,$length).$trailing;
        } else {
        $item_description = stripslashes($item_item["description"]);
        }
        echo "      $item_description<br />\n"
            .$item_item["length"]." ".$sys_config["unit_length"]." x "
            .$item_item["width"]." ".$sys_config["unit_length"]." x "
            ."      ".$item_item["height"]." ".$sys_config["unit_length"]
            ."    </div>\n"
            ."    </div>\n";
      }
    }
[/code]



Here's a log from the mysqld:

[code]  56 Query      SELECT * FROM `mod_inventory_category` WHERE `rid` = '0'  ORDER BY `name`
                56 Query      SELECT `product`.`name`, `product`.`description`, `product`.`height`, `product`.`length`, `product`.`width`, `product`.`weight`, `product`.`base_price`, `product`.`price_unit`, `item`.`iid`, `item`.`product_no`, `item`.`count`, `item`.`retail_price`, `item`.`status` FROM `mod_inventory_product` AS `product`, `mod_inventory_item` AS `item` WHERE `product`.`pid` = `item`.`pid` AND `product`.`cid` = '0'
                56 Query      SHOW PROCESSLIST
                56 Query      SHOW PROCESSLIST
                56 Query      SHOW PROCESSLIST
                56 Query      SHOW PROCESSLIST
                56 Query      SHOW PROCESSLIST
                56 Query      SHOW PROCESSLIST
                56 Query      SHOW PROCESSLIST
                56 Query      SHOW PROCESSLIST
                56 Query      SHOW PROCESSLIST
                56 Query      SHOW PROCESSLIST
                56 Query      SHOW PROCESSLIST
                56 Query      SHOW PROCESSLIST
                56 Query      SHOW PROCESSLIST
                56 Query      SHOW PROCESSLIST
                // Goes on and on...
[/code]
I have no clue why it's doing this...
Link to comment
https://forums.phpfreaks.com/topic/28810-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.