How to get data if there are many requests

This topic is a bit like another question of mine on dba.stackexchange.com, but the problem is different

I have two tables in my database, one of them is the user_app table, which stores information about the user, the table:

+--------------+--------------+------+-----+-------------------+-----------------------------+
| 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              |                             |
+--------------+--------------+------+-----+-------------------+-----------------------------+

Another table is an ad table through which I get an ad to a 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 case, I have to send one announcement to the user once every 24 hours, which I send in json format. In addition, if the user has installed our different applications, I have to send them only one ad in just a whole day. In this, package_name represents our applications, I am trying to achieve this using a flag time entry, for example:

$flag = date('dmy');

, . , .

: , , . , , . .

+5
1

:

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>';
+1

All Articles