【问题标题】:PHP mysql session arrayPHP mysql会话数组
【发布时间】:2018-11-21 15:55:53
【问题描述】:

我有一个小问题。

我在会话数组中存储的值很少。这些值是产品的 ID。 之后我想显示我的数据库中的产品,但这对我来说不能正常工作。 有人可以帮我一点吗? :)(我还在学习:))

<?php
include 'includes/dbconnect.php';
$orderid = $_SESSION['order'];
foreach ($orderid as $value) {
    $sql="SELECT * FROM product WHERE productID LIKE '%$value%'";
    $result=$conn->query($sql);
    while($row=$result->fetch_assoc()){ 
        echo '<tr>';
        echo '<td>'.$row["tag"].'</td>';
        echo '<td>'.$row["price"].',- Kč</td>';
        echo '<td><a href="product.php?id='.$row["productID"].'"><img src="images/'.$row["tag"].'.jpg" width=70"></a></td>';
        echo '<td>1</td>'   ;
        echo '<td><a href="#" class="btn btn-danger btn-lg">X</a></td>';
    }
}
?>

var_dump($orderid);显示:

array(1) {
    ["order"]=> array(10) {
        [0]=> string(2) "44"
        [1]=> string(2) "46"
        [2]=> string(2) "44"
        [3]=> string(2) "54"
        [4]=> string(1) "1"
        [5]=> string(2) "44"
        [6]=> string(1) "1"
        [7]=> string(2) "44"
        [8]=> string(2) "47"
        [9]=> string(2) "74"
    }
}

【问题讨论】:

  • 添加您收到的错误消息。如果没有更多有关问题所在的信息,我们无法为您调试此问题
  • 我没有看到 session_start()
  • 在 $sql 查询中而不是使用 LIKE '%$value%'"; 试试这个:LIKE '". $value ."'";
  • 哦,谢谢 Studocwho :) 就是这样! :) 非常感谢 :)
  • 为什么搜索简单却又复杂? x)@Studocwho 那么你只需要让它成为一个答案

标签: php mysql session


【解决方案1】:

仅出于 SO 的目的,我将发表评论作为答案:

在 $sql 查询中而不是使用 LIKE '%$value%'"; 使用这个:LIKE '". $value ."'";

这样可以确保我们实际得到变量的值。

【讨论】:

猜你喜欢
  • 2018-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-05
  • 1970-01-01
  • 2019-06-21
相关资源
最近更新 更多