- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试使用 while 循环显示属于已登录用户的所有食谱。我注意到假设用户有 4 个食谱,第一个不会显示,导致表格中只出现 3 个食谱。如果用户有3个菜谱,第一个菜谱不会显示,导致只显示2个菜谱,以此类推。
我做了我的研究,发现这是因为第一行将被忽略,因此不会显示。
有没有人可以建议我应该对循环进行什么样的更正来解决这个问题?我的代码涉及在表格中显示,这就是为什么我仍然无法弄清楚尽管看了看应该做什么在已经发布和回答的其他问题上。
非常感谢!
<?php
// 0: Instead of hard coding I shall declare the value first
$userid = $_SESSION['userid'];
// 1: Connect to forumdb database
$mysqli = new mysqli("localhost", "root", null, "recipedb") or exit("Error connecting to database");
// 2: Prepare the statement to select recipename,recipeid,,imagefile belonging to the $userid from recipe table
$stmt = $mysqli->prepare("Select recipename,recipeid,imagefile from recipe where userid=?");
// 3: Bind the values
$stmt->bind_param("s", $userid);
// 4: Execute the statement
$stmt->execute();
// TODO 5: bind results into $recipename,$recipeid and $imagefile
$stmt->bind_result($recipename, $recipeid, $imagefile);
if ($stmt->fetch() == null) {
echo "You did not have any recipes yet.<br />";
}
else {
echo "<table style=width:100% >";
echo "<tr><td><b>Recipe</b></td><td><b>Actions</b></td></tr>";
// Use while loop to fetch messages and put in a <table>
// if
while ($stmt->fetch()) {
echo "<tr>";
// 6: In 1st <td>, display recipename,recipeid,imagefile
echo "<td><b>$recipename</b><br /><b>Recipe ID:</b>$recipeid<br /> <img src='images/$imagefile' height='125' width='125' > </td>";
// 7: In 2nd <td>, display View hyperlink
// The View hyperlink links to recipedetails.php
// The delete hyperlink links to deleterecipes.php
echo "<td> <a href='recipedetails.php?recipeid=$recipeid'>View</a> ";
echo "<a href='deleteconfirmation.php?recipeid=$recipeid'>Delete</a> ";
echo "</tr>";
}
echo "</table>";
}
// 8: close the statement
$stmt->close();
// 9: close $mysqli
$mysqli->close();
?>
最佳答案
正如您所说,当您这样做时:
if($stmt->fetch()==null)
代码获取第一行。如果不存在,则条件触发。否则,它会继续,当您开始“真正地”获取行时,第一行已经被获取。
您可以改为检查返回的行数:
$stmt->store_result();
if ($stmt->num_rows == 0) {
echo "You did not have any recipes yet.<br>";
}
关于php - while ($stmt->fetch()) 不获取所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28383262/
我正在运行此代码并在没有互联网连接的情况下进行测试: fetch(url, options) .then(res => { // irrelevant, as catch happens
function fetchHandler(evt) { console.log('request:' + evt.request.url); dealWithRequest(evt)
我在 AdventureWorks2016 上执行了两个示例查询,并得到了相同的结果。那么什么时候应该使用 NEXT 或 FIRST 关键字? select LastName + ' ' + Firs
我有以下查询: @Query("SELECT new de.projectemployee.ProjectEmployee(employee) " + "FROM ProjectEmpl
我正在尝试使用 fetch on react 来实现客户端登录。 我正在使用护照进行身份验证。我使用的原因 fetch而不是常规 form.submit() , 是因为我希望能够从我的快速服务器接收错
我正在尝试将我的 Aurelia 项目从 beta 版本升级到 3 月版本。 我遇到的错误之一是: Cannot find name 'Request'. 谷歌搜索会在 GitHub 上显示此问题:h
见标题。在我们的react项目中调用fetch时,一位(现已离职)开发人员最初使用from fetch to window.fetch。我不确定两者之间的区别,也无法在网上找到任何结论(W3Schoo
这个问题在这里已经有了答案: HTTP status code 401 even though I’m sending credentials in the request (1 个回答) How
这是代码片段: var fetch = require("node-fetch"); var fetchMock = require("fetch-mock"); function setupMock
我在这里看到了两种不同的抓取方式: https://github.com/github/fetch https://github.com/matthew-andrews/isomorphic-fetc
以下git命令有什么区别? git fetch origin 和 git fetch --all 从命令行运行它们看起来就像它们做同样的事情。 最佳答案 git fetch origin 仅从 ori
我有一个不断改变值的动态 json。我想用该数据绘制图表所以我将动态数据存储到数组然后用该数组绘制图表。目前我创建了 serinterval 用于从 api 获取新数据。但问题是如果新数据没有,它会再
我有一个很大的 JSON blob,我想预先加载我的网页。为此,我添加了 到我的页面。我也有一个 JS 请求来获取相同的 blob。 这不起作用,控制台报告: [Warning] The resour
我们在单页 JavaScript 应用程序发出 fetch 请求时遇到不一致的客户端错误。值得注意的是,它们都是同源请求。 let request = new Request(url, options
我是 ReactJS 的新手,我一直在阅读如何从 api 获取和发布数据。我见过这两个,但我不知道该用什么以及两者之间有什么区别?我读了它,但我不确定我会用什么。谢谢! react-fetch wha
Doctrine中注解@ManyToOne中的fetch="EAGER"和fetch="LAZY"有什么区别? /** * @ManyToOne(targetEntity="Cart", casca
我想要获取一个 api,然后调用另一个 api。在 javascript 中使用这样的代码是否明智? fetch(url, { method: 'get', }).then(function(re
我有一个组件,它依赖于 2 个端点来检索所需程序的名称。我有 2 个端点。第一个端点返回程序列表,它是一个对象数组。目前,它仅返回 4 个节目(2 个节目 ID 为“13”,另外两个节目 ID 为“1
我的应用程序从外部源(配置文件)接收查询,因此它必须从查询结果中获取列。我有一些代码: typedef union _DbField { text text[512]; sword i
我有一个实体A,它与实体B有对多关系。 Entity A -->> Entity B 我需要在多个屏幕上引用一对多关系的计数。此外,我可以多次从 Entity A
我是一名优秀的程序员,十分优秀!