如何在php中显示没有唯一值(id)的模态的特定数据

时间:2016-12-15 11:25:40

标签: php jquery twitter-bootstrap pagination

我的数据集来自API。数据中没有id属性。当我们想要在模态中显示其id的基础上的特定数据时,我们在data-id中声明了html属性,但是如果我们没有与数据关联的任何id。我们如何在模态上显示它的内容?

查看数据,我正在显示name,并more-info拥有modal按钮。当有人点击more-info按钮时,该怎么办?它显示具体内容?

数据中还有一个下一个url如何在php中对它进行分页?

{
"count": 37, 
"next": "http://some-url/api/stars/?page=2", 
"previous": null, 
"results": [
    {
        "name": "Sentinel-class landing craft", 
        "model": "Sentinel-class landing craft", 
        "manufacturer": "Sienar Fleet Systems, Cyngus Spaceworks", 
        "cost_in_credits": "240000", 
        "length": "38", 
        "max_atmosphering_speed": "1000", 
        "crew": "5", 
        "passengers": "75", 
        "cargo_capacity": "180000", 
        "consumables": "1 month", 
        "hyperdrive_rating": "1.0", 
        "MGLT": "70", 
        "starship_class": "landing craft", 
        "pilots": [], 
        "films": [
            "http://some-url/api/films/1/"
        ], 
        "created": "2014-12-10T15:48:00.586000Z", 
        "edited": "2014-12-22T17:35:44.431407Z", 
        "url": "http://some-url/api/stars/5/"
    }, 
    {
        "name": "Death Star", 
        "model": "DS-1 Orbital Battle Station", 
        "manufacturer": "Imperial Department of Military Research, Sienar Fleet Systems", 
        "cost_in_credits": "1000000000000", 
        "length": "120000", 
        "max_atmosphering_speed": "n/a", 
        "crew": "342953", 
        "passengers": "843342", 
        "cargo_capacity": "1000000000000", 
        "consumables": "3 years", 
        "hyperdrive_rating": "4.0", 
        "MGLT": "10", 
        "starship_class": "Deep Space Mobile Battlestation", 
        "pilots": [], 
        "films": [
            "http://some-url.co/api/films/1/"
        ], 
        "created": "2014-12-10T16:36:50.509000Z", 
        "edited": "2014-12-22T17:35:44.452589Z", 
        "url": "http://some-url.co/api/starships/9/"
    }, 

1 个答案:

答案 0 :(得分:0)

$arrayData = json_decode($jsonData);
$i=0;
foreach($arrayData->results as $data)
{   
    $arrayData->results[$i]->name;
    $arrayData->results[$i]->id=$i;
    $i++;
}