ios - Get MySQL data and store it to a PHP array based on the data array returned by another MySQL select operation -
i creating ios application , facing difficulty web service portion, written in php. trying achieve is, sending push notification devices. have completed part. however, need mechanism differentiate between notifications has been delivered phone , haven't. use feedback web-service purpose , working. have mysql table following structure. based on status bit of each notification, collect notifications corresponding each device token, , make array , send device. here facing difficulty.
i have 2 tables.
this table stores notification id, device token , status of notification. looking @ table, script can determine whether notification has been delivered particular device or not. script collects notification ids has been undelivered particular device id , uses following apps_notif table fetch undelivered notifications. table structure below.
my php/mysql script follows.
$fecthnotif=mysqli_query($mysqli,"select notif_id notif_status notif_status=0 , dev_token='$device_token'") or die(mysqli_error($mysqli)); $d2=array(); while($row = mysqli_fetch_assoc($fecthnotif)) { $d2[]=$row; $json = json_encode($d2); $arr = json_decode( $json,true);
by time, array of undelivered notifications json. result follows.
[{"notif_id":"124"},{"notif_id":"129"}]
now, loop though results follows.
foreach($arr $item) { //foreach element in $arr $uses= $item['notif_id']; }
what trying achieve take each notif_id above result, fetch allthe notification data apss-notif table, make single json object , return payload app.so json should have notification data of notifications undelivered @ first place.
inside foreach loop, wrote query loop store pending notifications array, isnt working.
$d=array(); foreach($arr $item) { //foreach element in $arr $uses= $item['notif_id']; //etc //echo $uses; $sendnotif=mysqli_query($mysqli,"select * apps_notif notif_id='$uses'") or die(mysqli_error($mysqli)); while($row = mysqli_fetch_assoc($sendnotif)) { $d[]=$row; $i++; } }
edit: basically, trying achieve return rows apps_notif table match criteria, notif_status=0 (from table notif_status) , dev_token="qwerty" (from apps_notif table)
i can see 2 rows eligible.
hope helps
select b.* notif_status inner join apps_notif b on a.notif_id = b.notif_id notif_status = 0 , dev_token = '$device_token';
using sub queries,
select * app_notify notify_id in (select notif_id notif_status notif_status = 0 , dev_token = '$device_token') ;
see in table. in table 1 have notify_id
in table 2
have date
having kind of similar values. hence if u match table1 notifyid
, table2 notifyid
not desired output. first check proper criteria how table should designed.
Comments
Post a Comment