php 遍历一个表所有的内容
<HTML><HEAD><TITLE>OurListofJokes</TITLE></HEAD><BODY><?php$conn=mysql_connect("local...
<HTML>
<HEAD>
<TITLE>Our List of Jokes</TITLE>
</HEAD>
<BODY>
<?php
$conn = mysql_connect ( "localhost:3306", "root", "123" );
if (!$conn) {
echo ("<P>Unable to connect to the " . "database server at this time.</P>");
exit ();
}
if (! mysql_select_db ( "dz" ) ) {
echo( "<P>Unable to locate the joke " . "database at this time.</P>" );
exit();
}
?>
<P>Here are all the jokes in our database:</P>
<BLOCKQUOTE>
<?php
$result = mysql_query ( "SELECT * FROM user" );
if (! $result) {
echo ("<P>Error performing query: " . mysql_error () . "</P>");
exit ();
}
while ( $row = mysql_fetch_array ( $result ) ) {
foreach ($row as $i){
echo ("<P>" . $i . "</P>");
}
}
?>
</BLOCKQUOTE>
</BODY>
</HTML>
只输出了第一行,而且还重复输出了2次,我菜鸟,不知道怎么改....
我想把$row中所有的数据(也就是SELECT * FROM user的结果)都打出来,怎么做? 展开
<HEAD>
<TITLE>Our List of Jokes</TITLE>
</HEAD>
<BODY>
<?php
$conn = mysql_connect ( "localhost:3306", "root", "123" );
if (!$conn) {
echo ("<P>Unable to connect to the " . "database server at this time.</P>");
exit ();
}
if (! mysql_select_db ( "dz" ) ) {
echo( "<P>Unable to locate the joke " . "database at this time.</P>" );
exit();
}
?>
<P>Here are all the jokes in our database:</P>
<BLOCKQUOTE>
<?php
$result = mysql_query ( "SELECT * FROM user" );
if (! $result) {
echo ("<P>Error performing query: " . mysql_error () . "</P>");
exit ();
}
while ( $row = mysql_fetch_array ( $result ) ) {
foreach ($row as $i){
echo ("<P>" . $i . "</P>");
}
}
?>
</BLOCKQUOTE>
</BODY>
</HTML>
只输出了第一行,而且还重复输出了2次,我菜鸟,不知道怎么改....
我想把$row中所有的数据(也就是SELECT * FROM user的结果)都打出来,怎么做? 展开
2个回答
展开全部
while ( $row = mysql_fetch_array ( $result ) ) {
echo ("<P>" . $row['这里填你的字段名'] . "</P>");
}
个人觉得你while了又foreach实际应用上应该是很少这样子用的。
echo ("<P>" . $row['这里填你的字段名'] . "</P>");
}
个人觉得你while了又foreach实际应用上应该是很少这样子用的。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<?php
$conn = mysql_connect ( "localhost:3306", "root", "123" );
if (!$conn) {
echo ("<P>Unable to connect to the " . "database server at this time.</P>");
exit ();
}
if (! mysql_select_db ( "dz" ) ) {
echo( "<P>Unable to locate the joke " . "database at this time.</P>" );
exit();
}
?>
<P>Here are all the jokes in our database:</P>
<BLOCKQUOTE>
<?php
$result = mysql_query ( "SELECT * FROM user" );
if (! $result) {
echo ("<P>Error performing query: " . mysql_error () . "</P>");
exit ();
}
$row = mysql_fetch_array($result);
foreach ($row as $i){
echo ("<P>" . $i . "</P>");
}
?>
数据库里有两个记录吧?
$conn = mysql_connect ( "localhost:3306", "root", "123" );
if (!$conn) {
echo ("<P>Unable to connect to the " . "database server at this time.</P>");
exit ();
}
if (! mysql_select_db ( "dz" ) ) {
echo( "<P>Unable to locate the joke " . "database at this time.</P>" );
exit();
}
?>
<P>Here are all the jokes in our database:</P>
<BLOCKQUOTE>
<?php
$result = mysql_query ( "SELECT * FROM user" );
if (! $result) {
echo ("<P>Error performing query: " . mysql_error () . "</P>");
exit ();
}
$row = mysql_fetch_array($result);
foreach ($row as $i){
echo ("<P>" . $i . "</P>");
}
?>
数据库里有两个记录吧?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询