<?php
$connection = mysql_connect('localhost', 'root', '1234');
mysql_select_db('database');
$query = "SELECT user_name FROM users";
while($row = mysql_fetch_array($result)){
echo '<div class="mosaic-block bar2" onmouseout="decolorit2()" onmouseover="colorit2()">'
'<a target="_blank" class="mosaic-overlay">'
'<div class="details">'
'<p class="font_us">' . $row['user_name'] . '</p> <br/>'
'<p class="font_us1">technische Umsetzung</p>'
'</div>'
'</a>'
'<div class="mosaic-backdrop"><img id="pic" src="../views/pictures/pic"/></div>'
'</div>';
}
mysql_close();
?>
所以我想用一些javascript效果输出我的数据库的用户名,但它没有显示。我该怎么回应呢?
答案 0 :(得分:2)
echo 'foo
bar
baz';
无需关闭每个换行符的引号。不过更好,只需退出PHP模式:
<?php while ($row = mysql_fetch_array($result)) { ?>
<div>
...
<?php echo $row['user_name']; ?>
...
</div>
<?php } ?>
更好的可读性(IMO):
<?php while ($row = mysql_fetch_array($result)) : ?>
...
<?php endwhile; ?>
答案 1 :(得分:0)
您应该使用pdo
或mysqli
你没有连接你的字符串。
<?php
$connection = mysql_connect('localhost', 'root', '1234');
mysql_select_db('database');
$query = "SELECT user_name FROM users";
while($row = mysql_fetch_array($result)){
echo '<div class="mosaic-block bar2" onmouseout="decolorit2()" onmouseover="colorit2()">'.
'<a target="_blank" class="mosaic-overlay">'.
'<div class="details">'.
'<p class="font_us">' . $row['user_name'] . '</p> <br/>'.
'<p class="font_us1">technische Umsetzung</p>'.
'</div>'.
'</a>'.
'<div class="mosaic-backdrop"><img id="pic" src="../views/pictures/pic"/></div>'.
'</div>';
}
mysql_close();
?>