while 循环中 echo 内的换行符
再次快速提问,我确信这非常简单,但我不明白我做错了什么!
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<a href=\"http://mysite.com/{$row['row1']}/{$row['row2']} \">{$row['row3']} </a>";
}
这使得我的所有链接都被一个接一个地堆叠起来。我想在列表中对它们进行排序,所以我尝试过:
echo "<ul>";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<li><a href=\"http://mysite.com/{$row['row1']}/{$row['row2']} \">{$row['row3']} </a> </li>";
}
echo "</ul>" ;
并且
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<a href=\"http://mysite.com/{$row['row1']}/{$row['row2']} \">{$row['row3']} </a> <br />";
}
我希望看到的最终结果是:
-链接1
-链接2
-链接3
-链接4
我做错了什么?提前致谢!
Quick question, again, I'm sure this is ridiculously simple but I don't see what I'm doing wrong!
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<a href=\"http://mysite.com/{$row['row1']}/{$row['row2']} \">{$row['row3']} </a>";
}
This produces all my links to be stacked up one after the other. I want to order them in a list so I have tried:
echo "<ul>";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<li><a href=\"http://mysite.com/{$row['row1']}/{$row['row2']} \">{$row['row3']} </a> </li>";
}
echo "</ul>" ;
and
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<a href=\"http://mysite.com/{$row['row1']}/{$row['row2']} \">{$row['row3']} </a> <br />";
}
The ultimate result I wish to see is :
-Link 1
-Link 2
-Link 3
-Link 4
What am I doing wrong? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我看不出有什么问题。即使是
也应该可以工作:I can't spot anything wrong with it. Even a
<br/>
should work:使用
echo "
use
echo "<a href="…>link</a>\n
to add a newline in the generated sourcecode试试这个
Try this
对于 HTML 中的换行符,请尝试使用
,您的代码可能看起来像这样:编辑
另请注意,如前面的评论中所述,
是不需要的,如果我将其从代码中取出,我的输出将保持不变。我制作了一个类似的测试 php 文件,并使用了上面的建议并且工作正常,这是我的代码
显示如下:
For a line break in HTML try using
<br />
, your code can look like something along this line:EDIT
Also note, as mentioned before in the comments,
<br />
isn't needed, if I take it out of my code my output stays the same.I made a test php file similar and used my suggestion above and works fine, here is my code
Displayed below: