Jump to content

PHP Mysql decrease connections


funstad

Recommended Posts

I'm looking for a way to decrease the number of MYSQL connections made to update my MYSQL table.

 

I know a little about the JOIN MYSQL but i was not able to implement it without the code be broken.

 

The current code i have:

<?php      // 1: Get id from stock available. $Get_ID_Stock= mysql_query('SELECT id_stock_available FROM shop_stock_available') or die(mysql_error());while( $row = mysql_fetch_assoc( $Get_ID_Stock)){    $ID_Stock_array[$row['id_stock_available']]['id'] = $row['id_stock_available'];}// 2: Put stock available id's in a array loopforeach($ID_Stock_array as $array) {       $isa = $array['id'];  $Get_ID_Attribute = "SELECT id_product_attribute FROM shop_stock_available WHERE id_stock_available = '$isa' ";     $Set_ID_Attribute = mysql_query($Get_ID_Attribute) or die(mysql_error());  while($Row_ID_Attribute = mysql_fetch_array($Set_ID_Attribute)) {   $ipa = $Row_ID_Attribute['id_product_attribute'];    $Get_Combination = "SELECT id_attribute FROM shop_product_attribute_combination WHERE id_product_attribute = '$ipa' ";      $Set_Combination = mysql_query($Get_Combination) or die(mysql_error());    while($Row_Combination = mysql_fetch_array($Set_Combination)) {    $value = $Row_Combination['id_attribute'];              // If id is between 1 and 31 its attribute "id_framemaat"    if (($value >= 1 && $value <= 31)) { $framemaat_id = $value; }          // If id is between 35 and 37 its attribute "id_soort"    if (($value >= 35 && $value <= 37)) { $soort_id = $value; }      $Get_Ean13 = "SELECT ean13 FROM shop_product_attribute WHERE id_product_attribute = '$ipa' ";           $Set_Ean13 = mysql_query($Get_Ean13) or die(mysql_error());      while($Row_Ean13 = mysql_fetch_array($Set_Ean13)) {      $IPAean13 = $Row_Ean13['ean13'];        $Get_Quantity = "SELECT COUNT(id_soort) AS qty FROM Adcount_input         WHERE ean13 = '$IPAean13' AND id_soort = '$soort_id' AND id_framemaat = '$framemaat_id' ";        $Set_Quantity = mysql_query($Get_Quantity) or die(mysql_error());        while($Row_Quantity = mysql_fetch_array($Set_Quantity)) {        $final_quantity = $Row_Quantity['qty'];          mysql_query("UPDATE shop_stock_available SET quantity='$final_quantity' WHERE id_stock_available = '$isa' ")          or die(mysql_error());              echo 'Updated quantity: '.$isa.' to '.$final_quantity.'<br />';         }      }    }     }  }?>
Link to comment
Share on other sites

  • 2 weeks later...
SELECT id_stock_available FROM shop_stock_availableSELECT id_product_attribute FROM shop_stock_available WHERE id_stock_available = '$isa'
You should select both columns in the first query instead of looping through the results and selecting another column for each result. It looks like you can also join on the shop_product_attribute_combination, shop_product_attribute, and Adcount_input tables. What have you tried so far?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...