我正在尝试在另一个准备好的语句中包含准备好的语句

问题描述 投票:0回答:1

在此给定的准备好的语句中,它获得了文章标题。当它获得文章标题时,还应该将该变量发送到另一个准备好的语句中,该语句然后查找给定文章的浏览量。

<table class="table table-colored table-centered table-inverse m-0">
<thead>
<tr>

<th>Title</th>
<th>Category</th>
<th>Writer</th>
<th>Action</th>
<th>Views</th>
</tr>
</thead>
<tbody>


<?php
$stmt = $con -> prepare('select tblposts.id as postid,tblposts.PostTitle as title,tblposts.PostUrl as postname, tblcategory.CategoryName as category,tblwritter.Writter as writter from tblposts left join tblcategory on tblcategory.id=tblposts.CategoryId left join tblwritter on tblwritter.WritterId=tblposts.WritterId where tblposts.Is_Active=?');
$cnt=1;
$stmt -> bind_param('i', $cnt);
$stmt -> execute();
$stmt -> store_result();
$stmt -> bind_result($postid,$title,$postname,$category,$writter);
?>

 <tr>
<?php while ($stmt->fetch()){?>
<td><b><?php echo $postname;?></b></td>
<td><?php echo $category?></td>
<td><?php echo $writter?></td>


<td>
<a href="edit-post.php?pid=<?php echo $postid;?>"><i class="fa fa-pencil" style="color: #29b6f6;"></i></a>
    &nbsp;<a href="manage-posts.php?pid=<?php echo$postid;?>&&action=del" onclick="return confirm('Do you reaaly want to delete ?')"> <i class="fa fa-trash-o" style="color: #f05050"></i></a>
</td>

<?php
$stmt = $con -> prepare('select COUNT(ip) FROM tblviews WHERE postname = ?');
$stmt -> bind_param('s', $postname);
$stmt -> execute();
$stmt -> store_result();
$stmt -> bind_result($ip);
?>
<?php while ($stmt->fetch()){?>
<td><?php echo $ip ?></td>
<?php } ?>

 </tr>


<?php }?>
                                            </tbody>
                                        </table>

此代码的预期结果是将邮政名发送到准备好的语句中,然后在任何给定的文章中调用视图的数量。

php html mysql mysqli prepared-statement
1个回答
0
投票

简短回答:您正在循环中覆盖$stmt

© www.soinside.com 2019 - 2024. All rights reserved.