doufu9521 2012-01-05 01:25
浏览 33
已采纳

PHP echo同名的POST变量

Ok i have two tables with a left join. Let call table one "people" and the second table "dog". I have left joined the tables by an id:

"SELECT * FROM people
      LEFT JOIN dog ON people.PK = dog.fk"; 

My problem is that both tables have a column title "name." When i echo back out the $_POST['name'] variable it give the same value for both fields I tried

echo $_POST['people.name']
echo $_POST['dog.name']

but this isn't returning any data so this must be incorrect. Can someone help me fix my problem without having to change my column names. Thanks you.

  • 写回答

2条回答 默认 最新

  • dpblwmh5218 2012-01-05 01:32
    关注

    The $_POST superglobal contains data submitted from a form. It does not contain data from database queries. You probably do something like this (pseudocode):

    $result = database_query (
        "SELECT * FROM people LEFT JOIN dog ON people.PK = dog.fk"
    );
    

    The data you want is now contained in the variable named $result. How you access it will depend on your database access method, but typically you would fetch a row from the result object, perhaps as an associative array.

    $row = database_fetch_assoc($result);
    

    Then the array $row would contain your data.

    echo $row['name'];
    

    You might need to alias the column names in the query in order to be able to access the values of both name columns.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥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做蓝牙接受端