简体   繁体   English

PHP / MySQL查询-显示数据刷新器[代码语法正确吗?]

[英]PHP/MySQL query - displaying data refresher [is code syntax correct?]

This is my page from an online radio station site of mine on localhost, it's a basic PHP/MySQL one for test purposes: 这是我在本地主机上的在线广播站点上的页面,它是用于测试目的的基本PHP / MySQL:

    <?php
mysql_connect('localhost', 'root', 'mypass') or die (mysql_error());
mysql_select_db('radiotest') or die (mysql_error());
$result = mysql_query("SELECT *, TIME_FORMAT(airtime, '%H:%i') `airtime` 
from presenters");
//Table starting tag and header cells
while($row = mysql_fetch_array($result)){
//Display the results in different cells
echo "<dd><dl><img src=' " . $row['image'] . " '>" . $row['airtime'] ." 
" . $row['presenter'] . "</dd></dl>";
echo "<dd><dl>" . $row['showinfo'] . "</dd></dl>";
}
?>

It works properly, displays the data from the table in the required format. 它可以正常工作,并以所需格式显示表中的数据。

However, I want to try doing it this way: 但是,我想尝试这样做:

<dd><dl><img src='<?php echo $row['image'] ?'> <?php echo $row['airtime']?> 
 <?php echo. $row['presenter']?> </dd></dl>

My problem: I admit I've forgotten how to do echo without displaying it in the PHP/MySQL query like above, so how can I ensure it displays the variables using echo without having to declare it in the MySQL connection? 我的问题:我承认我忘记了如何做回声而不在上面的PHP / MySQL查询中显示它,那么如何确保它使用回声显示变量而不必在MySQL连接中声明它呢? I know my original is correctly formatted, but I don't want it to have the echo variables after the while part of the syntax, I wanted to echo them within the dd / dl HTML (definition list). 我知道我的原件格式正确,但是我不希望它在语法的while部分之后有echo变量,我想在dd / dl HTML(定义列表)中回显它们。

Basically, I'm just trying to brush up my skills in this area; 基本上,我只是想在这方面提高自己的技能。 had a look on Google but am not quite sure 在Google上看过,但不太确定

Any help is appreciated! 任何帮助表示赞赏!

It's really no different, and definitely not better, but I think you are asking to do: 确实没有什么不同,而且绝对没有更好,但是我认为您要这样做:

while($row = mysql_fetch_array($result)){
//Display the results in different cells
?>
<dd><dl>
    <img src='<?php echo $row['image']; ?>'>
    <?php echo $row['airtime']; ?> <?php echo $row['presenter']; ?>
</dd></dl>
<dd><dl>'<?php echo $row['showinfo']; ?></dd></dl>
<?php
}

Try this instead: 尝试以下方法:

<dd>
    <dl>
        <img src='<?=$row['image'] ?>'> <?=$row['airtime'] . " - " .$row['presenter']?> 
    </dd>
</dl>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM