php - 我的代码没有在前端显示数据库值。谁能帮我?
问题描述
我试图用 id 显示我的数据库表的名称,但它不起作用。谁能帮我解决问题在哪里?
它说成功添加了类别中的数据,但上面的代码无法在表格中显示。
代码:
<table class="table table-hover">
<tr>
<th>Sr No.</th>
<th>Category Name</th>
</tr>
<? php
global $connectiondb;
$ViewQuery="SELECT * FROM category";
$Execute=mysqli_query($connection, $ViewQuery);
$SrNo=0;
while ($DataRows=mysqli_fetch_array($Execute,MYSQLI_BOTH);) {
$Id=$DataRows["id"];
$CategoryName=$DataRows["name"];
$SrNo++;
?>
<tr>
<td><? php echo $Id; ?></td>
<td><? php echo $CategoryName; ?></td>
</tr>
<? php } ?>
解决方案
尝试显示 SrNo 视图是否大于 0。如果 SrNo 大于 0,则意味着要显示的数据。请试试我的这段代码,看看它对你有没有帮助:
<table class="table table-hover">
<tr>
<th>Sr No.</th>
<th>Category Name</th>
</tr>
<?php
global $connectiondb;
$ViewQuery="SELECT * FROM category";
$Execute=mysqli_query($connection, $ViewQuery);
$SrNo=0;
while($DataRows=mysqli_fetch_assoc($Execute)) {
$Id=$DataRows["id"];
$CategoryName=$DataRows["name"];
$SrNo++;
?>
<tr>
<td><?php echo $Id; ?></td>
<td><?php echo $CategoryName; ?></td>
</tr>
<?php } ?>
</table>
推荐阅读
- python - AttributeError: 'super' object has no attribute '__getattr__' (我搜索过,但无济于事)
- ios - 应用程序将数据重置为零,即使它存储在 firebase
- react-native - React Native 使用 Twilio Programmable Chat 和 RN Gifted Chat
- html - 如何更改css中的字体?
- ios - 带有 AVCaptureVideoDataOutput 的 iOS 应用程序在 App Store 版本中崩溃
- python - 没有CUDA??在 Rstudio 上安装 keras/tensorflow 错误:错误:找不到 Python 模块 tensorflow.python.keras
- haskell - 循环图上的记忆遍历
- ruby-on-rails - Sublime Text & Source Tree 在 Excel VBA 中使用 xml.File 和 fsObject 生成的文件中看不到 FileDiff
- .net - .Net 远程设置 - 第一次请求后不起作用
- python - 为什么链接增强赋值会引发 SyntaxError