Hello. There is an order page, and data from several DB tables should pull up on it. But the fact is that when using mysql_fetch_assoc, it turns out to convert only the data into an associative array from the first table. When I try to use the function again, I get false in response.

I tried to push this function into another function - the result is the same. I tried to pull data from two tables with a query:

SELECT * FROM `modificators` , `pricing` 

In SQL, data is normally pulled up, but in PHP only the data from the first table.

In general, I do not even know what to do.

The code (in the comments showed where mysql_fetch_assoc is used):

 <?php function priceCalc($quantity_item, $modificator_sum, $item_price){ $total_amout = $quantity_item * ($item_price + $modificator_sum); return $total_amout; } function sqlDataQuery($sql_connection, $table, $other_request){ $sql_query = "SELECT * FROM `".$table."` ".$other_request; $sql_response = mysql_query($sql_query) or die("Invalid query: " . mysql_error()); return $sql_response; } require_once('db.php'); $sql_connection = dbConnect(); $sql_response = sqlDataQuery($sql_connection, 'modificators', ''); $input = []; $i = 0; while($row = mysql_fetch_assoc($sql_response)){ // ПЕРВОЕ ИСПОЛЬЗОВАНИЕ $input[$i] = $row; $i++; } $data = []; foreach($input as $d){ $gId = $d['id_group']; if(!isset($data[$gId])){ $data[$gId] = [ 'pricing' => [], 'names' => [] ]; } $data[$gId]['pricing'][] = $d['price']; $data[$gId]['names'][] = sprintf("%s %+.2f", $d['name'], $d['price']); } for($b = 0; $b < count($data); $b++){ $selected_rate = $_POST['mod'.$b]; $sum_modificators = $sum_modificators + $data[$b]['pricing'][$selected_rate]; } $get_price = mysql_fetch_assoc(sqlDataQuery($sql_connection, 'pricing', 'WHERE `id` = 1')); // ВТОРОЕ ИСПОЛЬЗОВАНИЕ echo priceCalc($_POST['items'], $sum_modificators, $get_price['price']); ?> 

    1 answer 1

    Most likely you need to transfer the connection by reference:

     function sqlDataQuery(&$sql_connection, $table, $other_request) 

    And it would be nice to clear the memory using (but this is purely for saving):

     mysql_free_result($sql_response); 
    • Returned error: Fatal error: Call-time pass-by-reference has been removed; Modify the declaration of sqlDataQuery (). In addition, the first mysql_fetch_assoc works, but the second does not. That is the problem. - Felix