It is impossible to build a multidimensional array. There are two MySQL tables: lost , history_lots .

An array is created from the first table. And in the second table we have to check if we really have such a lot, and if it is, then we find the ID in the array and set the my key to true . This is the very end of the array. Now, respectively, at the end everywhere "my":"false" .

My code is:

 $rows = array(); $query = "SELECT * FROM cs_lots WHERE active_lot='1'"; $res2 = mysql_query($query) or die(mysql_error()); $query = "SELECT DISTINCT id_lot FROM cs_lots_history WHERE user_steamid='".$_SESSION['steamid']."'"; $result1 = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($res2)) { $rows []= array( 'id' => $row['id'], 'inv_id' => $row['inv_id'], 'inv_assets' => $row['inv_assets'], 'name' => $row['inv_name'], 'inv_image' => $row['inv_image'], 'inv_rarity' => $row['inv_rarity'], 'inv_color' => $row['inv_color'], 'inv_type' => $row['inv_type'], 'inv_price' => $row['inv_price'], 'price_ticket' => $row['price_ticket'], 'maxUsers' => $row['places'], 'nowUsers' => $row['now_places'], 'my' => false ); } 

The array view itself:

 LOTS = [{"id":"166","inv_id":"989","inv_assets":"3432669422","name":"Redline ","inv_image":"image","inv_rarity":"Field-Tested","inv_color":"d32ce6","inv_type":"1","inv_price":"2105.97","price_ticket":"14","maxUsers":"240","nowUsers":"1","my":false}, {"id":"167","inv_id":"929","inv_assets":"3551634073","name":"Hyper Beast ","inv_image":"image","inv_rarity":"Battle-Scarred","inv_color":"eb4b4b","inv_type":"1","inv_price":"924.43","price_ticket":"8","maxUsers":"180","nowUsers":"0","my":false}, {"id":"168","inv_id":"1104","inv_assets":"3313740799","name":"Asiimov ","inv_image":"image","inv_rarity":"Battle-Scarred","inv_color":"eb4b4b","inv_type":"1","inv_price":"1495.00","price_ticket":"13","maxUsers":"180","nowUsers":"19","my":false}, {"id":"169","inv_id":"847","inv_assets":"3603670527","name":"Jaguar ","inv_image":"image","inv_rarity":"Battle-Scarred","inv_color":"eb4b4b","inv_type":"1","inv_price":"2711.65","price_ticket":"13","maxUsers":"320","nowUsers":"8","my":false}, {"id":"170","inv_id":"1100","inv_assets":"3313741398","name":"Asiimov ","inv_image":"image","inv_rarity":"Field-Tested","inv_color":"eb4b4b","inv_type":"1","inv_price":"2756.70","price_ticket":"16","maxUsers":"260","nowUsers":"10","my":false}, {"id":"171","inv_id":"899","inv_assets":"3551642235","name":"Atomic Alloy ","inv_image":"image","inv_rarity":"Factory New","inv_color":"d32ce6","inv_type":"1","inv_price":"862.50","price_ticket":"8","maxUsers":"180","nowUsers":"1","my":false}]; 

How can I get the result from the $result1 and compare it with the ID key in the array?

For example, if $result1_row['id_lot'] = $row['id'] - then at the end of the array body we write my:true .

  • nevertheless, you wrote some code in two hours, show it to us. maybe the task will become clearer - splash58
  • Update your question according to the guidelines for keeping discussions on Stack Overflow , instead of posting comments. If you have a new question, ask it separately, referring to this to provide context. - Nicolas Chabanovsky

1 answer 1

You can get the information you need in one two-table query. LEFT JOIN best. If there is no corresponding entry in the cs_lots_history table, NULL will be returned, the presence of which can be checked using the IS NULL construct. Depending on the result obtained, the my column can be set to true or false.

 SELECT l.id AS id, l.inv_id AS inv_id, l.inv_assets AS inv_assets, l.name AS name, l.inv_image AS inv_image, l.inv_rarity AS inv_rarity, l.inv_color AS inv_color, l.inv_type AS inv_type, l.inv_price AS inv_price, l.price_ticket AS price_ticket, l.places AS places, l.now_places AS now_places, IF(h.id_lot IS NULL, 0, 1) AS my FROM cs_lots AS l LEFT JOIN (SELECT DISTINCT id_lot FROM cs_lots_history WHERE user_steamid = '".$_SESSION['steamid']."') AS h ON h.id_lot = l.id WHERE l.active_lot = '1'