doubeiji2602 2017-12-18 09:46
浏览 124

从api调用id时未定义的变量

I'm working on a PHP project the teacher gave us, basically we have to make a website dynamic and create a liste.php with tasks stored in an API the teacher has.

So I have the index.php with the front page on it and the list of all the projects going on ( like trip preparation, shopping list and appartment decoration ). I created a liste.php with all the tasks contained in each project ( buying tickets, booking the hotel and buying a postcard for the trip preparation ).

Now I have to get all the tasks of each project from the API he gave us.

Here's the API

http://todo_api.xx.firstname-lastname.com/tache.php?liste_id=1

That's the API for project n°1, there are 3 projects in total ( I mentionned them all above )

I also have a functions.php with the $api_url stored, and 2 functions, one getting the list of projects, the other getting the tasks for each project.

$api_url = "http://todo_api.xx.firstname-lastname.com/";


function getAllListes(): array {
    global $api_url;

    $json = file_get_contents($api_url . "liste.php");
    return json_decode($json, true);
}



function getAllTaches(): array {
    global $api_url;
    $json = file_get_contents($api_url . "tache.php?liste_id=" . $id);
    return json_decode($json, true);
}

But when I try to print_r that, or even just display each task, I get this :

Notice: Undefined index: liste_id in /Applications/MAMP/htdocs/todo/database/functions.php on line 17

So obviously something is wrong, and this keeps me from going on. Any idea ?

Edit : here's my html/php code regarding the tasklist

$listes = getAllListes();
$taches = getAllTaches($id);

<ul>

        <?php foreach ($taches as $tache) : ?>
        <li><?php echo $tache["libelle"] ;?></li>
        <?php endforeach ; ?>
    </ul>

libelle is the index of the information required.

Thanks a lot !

  • 写回答

1条回答 默认 最新

  • doubo9799 2017-12-18 09:56
    关注

    Your code in functions.php

    function getAllTaches(): array { //declared function without parameter
    

    but html/php code

    $taches = getAllTaches($id);// calling the function with parameter.
    

    i guess if you pass the parameter to the function it will work.

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端