dongshadu4498 2013-03-07 18:45
浏览 59

数组空白回显问题

Hey working on a small project but I seem to be having a problem with a specific part of my code.

The first part works beautifully and displays products within a product category. http://mkiddr.com/phptests/shopping/category.php?id=2

However the issue seems to be having the category description to show, which is derived from a separate query into its own array. I have used

echo(mysqli_num_rows($result2));

This seems to count the correct amounts of rows from the query, indicating the SQL is working perfectly.

I would appreciate help on this I am a complete needbe and I have patched and edited this code to my needs (supplied by university). P.S I am aware there are vulnerabilities within security.

<?php
session_start();
include "conn.php";
include "header.php";

if (isset($_GET['id'])){
$CategoryID = $_GET['id'];
$q="SELECT ProductID, ProductName FROM Products WHERE CategoryID=$CategoryID";
$d="SELECT `Desc` FROM ProductCategories WHERE CategoryID=$CategoryID";

$result = mysqli_query($_SESSION['conn'],$q);
$result2 = mysqli_query($_SESSION['conn'],$d) or die(mysql_error());

echo "<div>";
while ($row = mysqli_fetch_row($result)){
    echo "<p><a href='product.php?id=".$row[0]."'>".$row[1]."</a></p>";
}
echo "</div>";
mysqli_free_result($result);

//Description
echo(mysqli_num_rows($result2)); //Test SQL

echo "<div>";
while ($myResult = mysqli_fetch_assoc($result2)){
    echo "<p>".$myResult[0]."</p>";
}
echo "</div>";
}
include "footer.php";
?>
  • 写回答

1条回答 默认 最新

  • dongxie548548 2013-03-07 18:47
    关注

    You're fetching wrong:

    while ($myResult = mysqli_fetch_assoc($result2)){
                                    ^^^^^--- produces a non-numerically keyed array
    

    You probably want

    echo $myResult['name_of_field']
    

    or

    mysqli_fetch_row($result2)
                 ^^^--returns a numerically keyed array.
    

    instead.

    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路