简体   繁体   English

显示来自phpmyadmin的数据

[英]display data from phpmyadmin

I'm a beginner in PHP5 and I'would like to have some help to get the code correct. 我是PHP5的初学者,希望获得一些帮助以使代码正确。 Check the code and I'will be grateful for your support. 检查代码,感谢您的支持。 index.php: index.php:

if ($tag == 'AfficherMesAnnonce')
{
    $Id_Utilisateur= $_GET['Id_Utilisateur'];
    $annonce = $db->MesAnnonces($Id_Utilisateur);
    if ($annonce) 
    {
        $response["success"] = 1;
        $response["annonce"]["Departure_place"] =$annonce["Departure_place"];
        $response["annonce"]["Departure_date"] = $annonce["Departure_date"];
        $response["annonce"]["Arrival_place"] = $annonce["Arrival_place"];
        $response["annonce"]["Path_type"] = $annonce["Path_type"];
        echo json_encode($response);
        // annonce stored successfully

    }else
    {
    $response["error_msg"] ="No annonce found";
    return false;
    echo json_encode($response);
    }
}

DB_Function.php: DB_Function.php:

  public function MesAnnonces($Id_Utilisateur)
{
$result = mysql_query("SELECT * FROM annonce WHERE Utilisateur_Id_Utilisateur = $Id_Utilisateur") or die(mysql_error());
    // check for result 
        while($row = mysql_fetch_assoc($result))
        {
        $dd[]=$row;
       }
            $response=array('annonce'=> $dd);
            return $response;
}

and thank you in advance. 并先谢谢您。

You DB function is creating the dd array as a collection of rows, and then nesting that as an element of what's returned. 您的DB函数正在将dd数组创建为行的集合,然后将其嵌套为所返回内容的元素。 But in your calling script you're assigning 但是在您的通话脚本中,您正在分配

$response["annonce"]["Departure_place"] = $annonce["Departure_place"]

--but the right side of that doesn't exist. -但是右边不存在。 You could instead assign: 您可以分配:

$response["annonce"]["Departure_place"] = $annonce[0][0]["Departure_place"]
  • which would be the first row. 这将是第一行。 You're not iterating through the rows in the client script, or using any kind of index to select a row. 您无需遍历客户端脚本中的行,也不必使用任何类型的索引来选择行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM