Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 数据库输出未显示。获取其他语句_Php_Mysql_If Statement_While Loop_Prepared Statement - Fatal编程技术网

Php 数据库输出未显示。获取其他语句

Php 数据库输出未显示。获取其他语句,php,mysql,if-statement,while-loop,prepared-statement,Php,Mysql,If Statement,While Loop,Prepared Statement,我有以下代码,我没有得到任何我的数据库输出出现在我的网站上。我只得到echo“这个主题不存在的else语句echo响应。”,但我的数据库中有主题 是否有人在我的代码中看到任何会导致它不显示任何输出并使else语句出现的内容?如果没有,我如何调试它来解决问题?我没有从我准备的语句中得到任何错误,因此它必须在numrows语句或while循环中 $con = mysqli_connect("localhost", "root", "", "db"); if (mysqli_connect_errno

我有以下代码,我没有得到任何我的数据库输出出现在我的网站上。我只得到
echo“这个主题不存在的else语句echo响应。

,但我的数据库中有主题

是否有人在我的代码中看到任何会导致它不显示任何输出并使else语句出现的内容?如果没有,我如何调试它来解决问题?我没有从我准备的语句中得到任何错误,因此它必须在numrows语句或
while
循环中

$con = mysqli_connect("localhost", "root", "", "db");
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
$cid = $_GET['cid'];
$tid = $_GET['tid'];
$userid = ( isset( $_SESSION['user'] ) ? $_SESSION['user'] : "" );

//Prepared SELECT stmt to get forum topics
$stmt = $con->prepare("SELECT * FROM forum_topics WHERE `category_id`=? AND id=? LIMIT 1");
if ( !$stmt || $con->error ) {
    die('Select topics prepare() failed: ' . htmlspecialchars($con->error));
}
if(!$stmt->bind_param('ii', $cid, $tid)) {
    die('Select topics bind_param() failed: ' . htmlspecialchars($stmt->error));
}
if(!$stmt->execute()) {
    die('Select topics execute() failed: ' . htmlspecialchars($stmt->error));
}
$numrows = $stmt->num_rows;
if($numrows == 1){
    echo "<table width='100%'>";
    if ( $_SESSION['user'] ) { 
        echo "<tr><td colspan='2'><input type='submit' value='Add Reply' onClick=\"window.location = 
    'forum_post_reply.php?cid=".$cid."$tid=".$tid."'\"> <hr />";
    } else {
        echo "<tr><td colspan='2'><p>Please log in to add your reply</p><hr /></td></tr>";
    }
    while($row = mysqli_fetch_assoc($stmt)){
        //Prepared SELECT stmt to get forum topics
        $stmt2 = $con->prepare("SELECT * FROM forum_posts WHERE `category_id`=? AND topic_id=?");
        if ( !$stmt2 || $con->error ) {
            die('Select topics prepare() failed: ' . htmlspecialchars($con->error));
        }
        if(!$stmt2->bind_param('ii', $cid, $tid)) {
            die('Select topics bind_param() failed: ' . htmlspecialchars($stmt2->error));
        }
        if(!$stmt2->execute()) {
            die('Select topics execute() failed: ' . htmlspecialchars($stmt2->error));
        }
        while($row2 = mysqli_fetch_assoc($stmt2)){
            echo "<tr><td valign='top' style='border: 1px solid #000000;'>
            <div style='min-height: 125px;'>".$row['topic_title']."<br />
            by ".$row2['post_creator']." - " .$row2['post_date']. "<hr />" . $row2['post_content'] ."</div></td>
            <td width='200' valign='top' align='center' style='border: 1px solid #000000;'>User Info Here!</td></tr>
            <tr><td colspan='2'><hr /></td></tr>";
        }
    }
} else {
    echo "<p>This topic does not exist.</p>";
}
引述:

返回结果集中的行数。使用
mysqli\u stmt\u num\u rows()
取决于是否使用
mysqli\u stmt\u store\u result()
在语句句柄中缓冲整个结果集

下面应该可以做到这一点:

$stmt->store_result();
$numrows = $stmt->num_rows;
if ($numrows == 1) {
    // etc...

没有帮助。不过谢谢。请在
phpmyadmin
中尝试此查询,认为您已经锁定了导致我出现此错误的添加操作….
警告:mysqli_fetch_assoc()期望参数1为mysqli_result,该行中给定的对象为
while($row=mysqli\u fetch\u assoc($stmt)){
如果我这样做,
while($row=$stmt->mysqli\u fetch\u assoc){
…我再也不会收到错误了,但是页面上的任何内容都不会超过该语句。我找到了它。我更改了这两个foreach语句。谢谢!
$stmt->store_result();
$numrows = $stmt->num_rows;
if ($numrows == 1) {
    // etc...