Не получается построить многомерный массив. Есть две таблицы MySQL: lost
, history_lots
.
Из первой таблицы создается сам массив. А во второй таблице мы должны проверять, есть ли у нас действительно такой лот, и, если он есть, то находим в массиве ID и присваиваем ключу my
значение true
. Это самый конец массива. Сейчас, соответственно, в конце везде "my":"false"
.
Мой код:
$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
);
}
Сам вид массива:
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}];
Каким образом я могу получить результат из запроса $result1
и сравнить его с ключом ID в массиве?
Например, если $result1_row['id_lot'] = $row['id']
- то тогда в конце тела массива пишем my:true
.