doujiushi9007
2017-02-19 17:13
浏览 47
已采纳

将带有数据值的列表中的值传递给mysql查询

I have a list

<ul id="my_ul">
<li data-value="1"><a href="test.php">111</a></li>
<li data-value="2"><a href="test.php">112</a></li>
<li data-value="3"><a href="test.php">113</a></li>
</ul>

I tried to pass the data-value on click event to MySQL query. I tried it with jQuery but when i var_dump the result its NULL.

Here is how i am getting the value

$('#my_ul').on("click", "li", function(){
   $.ajax("fetch_test.php",{method:"post", data:{val:$(this).attr("data-value")}}); 
});

and here is the fetch_test.php file code :

function showValue(){
include_once "connect.php";
$test=$_SESSION['val'];
$query="SELECT * FROM product INNER JOIN smetka on smetka.id=product.smetka_id WHERE product.smetka_id=$test";
$result=mysqli_query($conn,$query);
    $alert="";
        while($row=mysqli_fetch_array($result)){
            $alert .="<li data-value='$row[id]'><a href='test.php'>$row[name]";

            $alert .= "</a></li>";
        }
    return $alert;
}

How can i pass the data-value from the li?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题