PHP 中的 While 循环问题
我的 WHILE 循环有什么问题吗?
<?php
include('header.php');
$manage = "current_page_item";
include('nav.php');
include('sidebar.php');
?>
<div class="primary">
<br/>
<?php
$userId = $_GET['id'];
echo "<div class=\"item_list\">";
$sql = "SELECT * FROM user WHERE id = " . intval($userId);
$result = mysql_query($sql);
while($item = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<b>Title: </b>" . $item['item'] . "<br/><b>Email: </b>" . $item['email'] . "<br/>";
echo "<b>Price: </b>" . $item['price'] . "</b><br/><b>Category: </b>" . $item['category'] . "</b><br/> <b>Extra: </b>" . ($item['extra'] ."</b><br/><b>Date Listed: </b>". $item['date'];
}
echo "</div>";
?>
</div>
<?php include('footer.php'); ?>
Any suggestion of whats wrong with my WHILE Loop?
<?php
include('header.php');
$manage = "current_page_item";
include('nav.php');
include('sidebar.php');
?>
<div class="primary">
<br/>
<?php
$userId = $_GET['id'];
echo "<div class=\"item_list\">";
$sql = "SELECT * FROM user WHERE id = " . intval($userId);
$result = mysql_query($sql);
while($item = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<b>Title: </b>" . $item['item'] . "<br/><b>Email: </b>" . $item['email'] . "<br/>";
echo "<b>Price: </b>" . $item['price'] . "</b><br/><b>Category: </b>" . $item['category'] . "</b><br/> <b>Extra: </b>" . ($item['extra'] ."</b><br/><b>Date Listed: </b>". $item['date'];
}
echo "</div>";
?>
</div>
<?php include('footer.php'); ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你的错误就在这里。您使用了错误的变量名称来获取行:
应该是:
此外,最后一行在结束标记
?>
} >。我不知道它是否是被您在问题中遗漏的开放块所孤立的,或者它确实是错误地存在的。Your mistake is here. You're using the wrong variable name to fetch rows:
It should be:
Additionally, there's a loose closing brace
}
at the very last line just before the closing tag?>
. I don't know if it was orphaned by an opening block you left out of your question, or it was really there by mistake.除了
BoltClock
所说的和stoosh
之外,您还遇到了语法错误:您有两个没有任何意义的 paran,而我的赌注会导致语法错误。您确实应该将
error_reporting
设置为E_ALL
并将display_errors
设置为on
以进行开发!它使调试这些东西变得更加容易。更新
要为脚本临时设置它,请将其添加到顶部(当然在
之后)
Along with what
BoltClock
said andstoosh
, you also have a syntax error:You had two parans where they did not make any sense, and my bet cause a syntax error. You really should have
error_reporting
set toE_ALL
anddisplay_errors
set toon
for development! It makes debugging this stuff a ton easier.Update
To set that up temporary for a script add this to the top (after
<?php
of course)在第二条回显线上,有一些杂散的括号。应该是:
On the second echo line, you have a few stray parentheses. Sould be:
看来你的变量命名错误了?
您已在 while 函数参数中传递了
$userid
,但在循环中使用了$item
?除非您只发布了函数的片段,否则您还会获得额外的
}
。Seems like you've misnamed your variables?
You've passed
$userid
in your while function argument but you're using$item
in your loop?You've also got an extra
}
unless you've only posted a snippet of a function.删除最后一行的结束
}
。Remove the closing
}
on the last line.