dongrang2140 2015-11-17 11:30
浏览 36

未答复的PHP - 选择树状况列并显示其他3列

I want to display treeid, treelatitude and treelongitude by selecting the treecondition column.

When I POST "healthy" I am able to display treeid 4,6 & 7, But If I POST "Balanced" Not able to get treeid 1 & 8. How can I get it?

In my below code I can only able to display "Healthy" BUT not able to display "Balanced"

Please help to where exactly I am getting wrong in my code

Treeid   treelatitude  treelongitude  treeCondition
  1       12.33          17.22           Balanced
  2       12.33          17.22           Healthy
  3       12.33          17.33           Dieseased
  4       13.44          17.55           Healthy
  5       11.32          17.66           Imbalanced
  6       12.33          18.33           Healthy
  7       14.44          18.44           Healthy
  8       11.22          17.22           Balanced

<?php

define('__ROOT__', dirname(dirname(__FILE__))); 
require_once(__ROOT__.'/public_html/Config.php');


 // Connecting to mysql database
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);

 // json response array
 $response = array();


  $sq = "SELECT treeid, treelatitude, treelongitude FROM tree WHERE   (treecondition = 'Healthy','Balanced')";

 if (isset($_POST['treecondition'])) {

// receiving the post params

$treecondition = $_POST['treecondition'];

// get the tree details for google map marker
if($stmt = $mysqli->query($sq)){

   if ($stmt->num_rows) {


       while($tree = $stmt->fetch_assoc()) {

        $treeItem = array();

        $treeItem["treeid"] = $tree['treeid'];
        $treeItem["treelatitude"] = $tree['treelatitude'];
        $treeItem["treelongitude"] = $tree['treelongitude'];
        $response[] = $treeItem;

  }  echo json_encode($response);

  }

  }else {
     // user is not found with the credentials
    $response["error"] = TRUE;
   $response["error_msg"] = "Tree list view credentials are wrong. Please    try again!";
echo json_encode($response);
 }
 $mysqli->close();
 }
  • 写回答

2条回答 默认 最新

  • dsfsdfsdfsdf6455 2015-11-17 11:34
    关注

    It should be WHERE treecondition IN ('Healthy','Balanced')";

    EDIT

    Try this:

    $treecondition = $mysqli->real_escape_string($_POST['treecondition']);

    "SELECT treeid, treelatitude, treelongitude FROM tree WHERE treeCondition='{$treecondition}'"

    We have used real_escape_string to escape the characters posted directly. This would prevent SQL injection.

    Also MySQL is case sensitive please use treeCondition instead of treecondition

    评论

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题