【问题标题】:Passing Parameters in XML WebService in PHP/MYSQL在 PHP/MYSQL 中的 XML WebService 中传递参数
【发布时间】:2016-09-09 13:04:35
【问题描述】:

我是创建网络服务的新手。我在 XML 中创建了一个 Web 服务,如下所示:

<?php

     $con = mysqli_connect('localhost','root','','crmap');

     $query1="SELECT * FROM `crm_salesabsent_logsheet` WHERE `ab_date`=CURRENT_DATE()";
            $res=mysqli_query($con,$query1) or die(mysqli_error($con));
            $data= array();
            if(mysqli_num_rows($res)){
      while($row1=mysqli_fetch_assoc($res)){
          $data[] = array('row1'=>$row1);
      }
            }



      header('Content-type: text/xml');
            echo '<posts>';
            foreach($data as $index => $row1) {
                if(is_array($row1)) {
                    foreach($row1 as $key => $value) {
                        echo '<',$key,'>';
                        if(is_array($value)) {
                            foreach($value as $tag => $val) {
                                echo '<',$tag,'>',htmlentities($val),'</',$tag,'>';
                            }
                        }
                        echo '</',$key,'>';
                    }
                }
            }
            echo '</posts>';
    ?>

我没有在日期中传递任何参数,因为我将 Current_Date() 作为默认值。现在,我希望用户选择他们想要的日期。我想将日期作为参数传递并根据输入的日期显示查询结果。这是我试图在 MySQL 查询中将日期作为参数传递的 Html 代码

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>/title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<style>
    .dt{}

</style>
<script>

$(document).on('focus', '.dt', function() {$(this).datepicker({ dateFormat : 'dd-mm-yy'});});  
</script>
</head>

<body>
<form name="log" method="get">
 <table>
  <tr>
   <th>Select Date</th><td><input name="date" id="date" value="" class="dt"></td>
   <tr><td><input type="submit" name="post"  id="post" value="Submit"></td></tr>
  </tr>
 </table>
</form>
</body>
</html>

但我无法这样做,因为我收到错误消息。帮助和解决方案将不胜感激。 谢谢

【问题讨论】:

    标签: php html mysql xml web-services


    【解决方案1】:

    你可以替换这一行

    $query1="SELECT * FROM `crm_salesabsent_logsheet` WHERE `ab_date`=CURRENT_DATE()";
    

    这两行

    $date=date("Y-m-d", strtotime($_POST['date']));
    $query1="SELECT * FROM `crm_salesabsent_logsheet` WHERE `ab_date`='{$date}'";
    

    【讨论】:

    • 对不起,但这并没有回答我如何从输入字段中获取值从 html 到 xml 的问题
    【解决方案2】:

    要将发布的日期放入您的 XML 中,您可以添加如下一行:

    echo '<posts>';
    echo '<posted_date>' . date("Y-m-d", strtotime($_POST['date'])) . '</posted_date>';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-01
      • 1970-01-01
      • 2012-08-23
      • 1970-01-01
      • 2016-11-04
      • 2011-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多