本文介绍了如何使用span设置PHP echo输出的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望使用< span class = > < / span>< / code>为每个回音,但我不太确定如何实现这一点。
$ result = mysql_query(SELECT * FROM Blog);
while($ row = mysql_fetch_array($ result))
{
echo $ row ['Date'];
echo $ row ['Title'];
echo $ row ['Message'];
echo< img src ='。$ row ['Image']。'/>;
}
mysql_close($ con);
解决方案
$ result = mysql_query(SELECT * FROM Blog);
while($ row = mysql_fetch_array($ result))
{
echo< span class = \myclass\> $ row ['Date']<跨度>中;
echo< span class = \myclass \> $ row ['Title']< / span>;
echo< span class = \myclass \> $ row ['Message']< / span>;
echo< img src ='。$ row ['Image']。'/>;
}
mysql_close($ con);
或者更好的表格:
$ result = mysql_query(SELECT * FROM Blog);
回显< table>
while($ row = mysql_fetch_array($ result)){
echo< tr>
echo< td> $ row ['Date']< / td>;
echo< td> $ row ['Title']< / td>;
echo< td> $ row ['Message']< / td>;
echo< td>< img src ='。$ row ['Image']。'/>< / td>;
回声< / tr>
}
回显< / table>
mysql_close($ con);
然后,您可以使用类为每一行和每列设置样式。
I'm trying to style the output of each echo.
Ideally I'd like to use <span class=""> </span>
for each echo, but I'm not too sure how to achieve this.
$result = mysql_query("SELECT * FROM Blog");
while($row = mysql_fetch_array($result))
{
echo $row['Date'];
echo $row['Title'];
echo $row['Message'];
echo "<img src='".$row['Image']."'/>";
}
mysql_close($con);
解决方案
$result = mysql_query("SELECT * FROM Blog");
while($row = mysql_fetch_array($result))
{
echo "<span class=\"myclass\">$row['Date']</span>";
echo "<span class=\"myclass\">$row['Title']</span>";
echo "<span class=\"myclass\">$row['Message']</span>";
echo "<img src='".$row['Image']."'/>";
}
mysql_close($con);
or, much nicer, in a table:
$result = mysql_query("SELECT * FROM Blog");
echo "<table>"
while($row = mysql_fetch_array($result)) {
echo "<tr>"
echo "<td>$row['Date']</td>";
echo "<td>$row['Title']</td>";
echo "<td>$row['Message']</td>";
echo "<td><img src='".$row['Image']."'/></td>";
echo "</tr>"
}
echo "</table>"
mysql_close($con);
You then can style each row and column with a class.
这篇关于如何使用span设置PHP echo输出的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!