This topic is little similar to other question of mine on dba.stackexchange.com, but problem is different
I have two tables in my database, one is user_app table in which user info are stored, table are as:
+--------------+--------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+-------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| apikey | varchar(32) | NO | | NULL | |
| app_id | varchar(16) | NO | | NULL | |
| appidt | varchar(100) | NO | | NULL | |
| imei_num | varchar(32) | NO | MUL | NULL | |
| app_version | varchar(20) | NO | | NULL | |
| package_name | varchar(100) | NO | MUL | NULL | |
| stamp | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| sdk_version | float | NO | | NULL | |
+--------------+--------------+------+-----+-------------------+-----------------------------+
Other table is creative table through which i retrieve ad's to user:
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| campaign_id | tinyint(4) | NO | | NULL | |
| status | tinyint(4) | NO | | NULL | |
| type | varchar(20) | NO | | NULL | |
| title | varchar(40) | NO | | NULL | |
| description | varchar(100) | NO | | NULL | |
| iconlink | text | NO | | NULL | |
| marketlink | text | NO | | NULL | |
| app_id | varchar(16) | YES | | NULL | |
| package_name | varchar(200) | YES | MUL | NULL | |
+--------------+--------------+------+-----+---------+----------------+
Here is my php code:
$rss = $mysqli->query(" SELECT id as cid,
title, description,
iconlink, marketlink,
package_name FROM `creative`
WHERE package_name <> '".$pkg."' AND id = 16 "
);
$arr = array();
while($obj = $rss->fetch_object()) {
$arr = $obj;
}
//$uappid = $arr -> uid; //user app id for track
$cid = $arr -> cid; // creative id
//$campid = $arr -> campaign_id;
$title = $arr -> title;
$desc = $arr -> description;
$ilink = $arr -> iconlink;
$mlink = $arr -> marketlink;
$data = array('id'=>"$cid", 'title'=> "$title", 'description'=> "$desc", 'iconlink'=> "$ilink",'marketlink'=>"$mlink");
$creative = json_encode($data); //return creative json if imei is there
$response = array('success' => "true", 'result'=>"$creative", 'delay'=>"120000");
echo json_encode($response); //return ad in json
In this scenario, i have to send a single ad to user once in 24hr, which i am sending in json format. Also, if a user had installed our different apps, i have to send them only a single ad only in whole day. In this, package_name represent our applications, i am trying to achieve this via using a flag entry of time, like this:
$flag = date('dmy');
but how to achieve single ad per day, i am just research on this. Kindly look on this problem.
Update: My apologize, i am not mention it before, but i want to send only one ad to user out of lot of requests for ad's. For example user can send number of request's and install our app, then he doesn't get same ad on every request. He just received a single ad in whole day.
Try to add a multidimensional array of result query :
while($obj = $rss->fetch_object()) {
$array[$obj->cid]['cid'] = $obj->cid;
$array[$obj->cid]['title'] = $obj->title;
$array[$obj->cid]['description'] = $obj->description;
$array[$obj->cid]['iconlink'] = $obj->iconlink;
$array[$obj->cid]['marketlink'] = $obj->marketlink;
$array[$obj->cid]['package_name'] = $obj->package_name;
}
echo '<pre>';
var_dump(json_encode($array)); //return ad in json
echo '</pre>';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With