Hi i am an intermediate at php. I want to fetch data from a table and use that fetched data to select another item from a different table. And then put those all result values into an array.
My original php code is like below.
$res = mysqli_query($con, "select title, nickname, date, cos_id, likecount from A where area_tag='$tag'");
$result=array();
while($row=mysqli_fetch_array($res)){
array_push($result, array('title'=>$row[0], 'nickname'=>$row[1], 'date'=>$row[2], 'cos_id'=>$row[3], 'likecount'=>$row[4]));
}
echo json_encode(array("result"=>$result));
'cos_id' is a string value such as "ABC, Hello, Good". So if i get the cos_id from the table A, i want to split that String into "ABC", "Hello", "Good". Then use each String such as:
select name from B where tag='ABC',
select name from B where tag='Hello',
select name from B where tag='Good'
Eventually, i also want these three result values to put into array like
array_push($result, array('title'=>$row[0], 'nickname'=>$row[1], 'date'=>$row[2], 'cos_id'=>$row[3], 'likecount'=>$row[4], 'ABCResult'=>$row[5], 'HelloResult'=>$row[6], 'GoodResult'=>$row[7]));
Is this possible? I found some information of splitting String, however i have no idea how to select and put the new result values into the original result array.
Since the cos_id data is something like ABC,Hello,Good... select contentid, hit from B where tag IN (cos_id)
then i get some values like this. contentid hit 1111 1 2222 2 3333 3
I want to put these results into this array... array_push($result, array('title'=>$row[0], 'nickname'=>$row[1], 'date'=>$row[2], 'cos_id'=>$row[3], 'likecount'=>$row[4]));