是3个不同的表:专辑,单曲,即将推出。我想通过php嵌入所有三个。只有我嵌入的第一个表使用以下代码,另一个不使用:
<div id="album_releases" class="animated bounceIn">
<div id="headline">Latest Favorite Album Releases</div>
<div id="frame" class="frame">
<ul class="slidee">
<li><div id="datebox"><span style="padding-top:50px;">Oct<br />2013</span></div></li>
<?php
$sql = "SELECT artist, releasename, label, date, img, spotify, nas, itunes FROM album ORDER BY id DESC LIMIT 40";
$db_erg = $db_link->query( $sql );
function ausgabe($daten) {
echo "<li><div id='blurbox'><div class='blur img'><div class='img-wrap'><div class='img-info'>";
echo "". $daten->artist ."<br />";
echo "". $daten->releasename ."<br />";
echo "". $daten->label ."<br />";
echo "". $daten->date ."<br />";
echo "</div>";
echo "<img class='hover' width='168' height='168' src=". $daten->img .">";
echo "</div></div></div><div id='caption'>";
echo "<img src='images/spotifyicon.png' style='float:left;'><a href='". $daten->spotify ."'>Listen on Spotify</a><br />";
echo "<div id='element_sep'>-</div>";
echo "<img src='images/servericon.png' style='float:left;'><a href='". $daten->nas ."'>Listen on toegrNAS</a><br />";
echo "<div id='element_sep'>-</div>";
echo "<img src='images/itunesicon.png' style='float:left;'><a href='". $daten->itunes ."'>Listen/Buy on iTunes</a>";
echo "</div></li>";
}
while($daten = $db_erg->fetch_object()) {
ausgabe($daten);
}
?>
</ul>
</div>
<div id="overlay_left">-</div>
<div id="overlay_right">-</div>
</div>
<div id="single_releases" class="animated bounceIn">
<div id="headline">Latest Favorite Single Releases</div>
<div id="frame" class="frame">
<ul class="slidee">
<li><div id="datebox"><span style="padding-top:50px;">Oct<br />2013</span></div></li>
<?php
$sql = "SELECT artist, releasename, label, date, img, spotify, nas, itunes FROM single ORDER BY id DESC LIMIT 40";
$db_erg = $db_link->query( $sql );
function ausgabe($daten) {
echo "<li><div id='blurbox'><div class='blur img'><div class='img-wrap'><div class='img-info'>";
echo "". $daten->artist ."<br />";
echo "". $daten->releasename ."<br />";
echo "". $daten->label ."<br />";
echo "". $daten->date ."<br />";
echo "</div>";
echo "<img class='hover' width='168' height='168' src=". $daten->img .">";
echo "</div></div></div><div id='caption'>";
echo "<img src='images/spotifyicon.png' style='float:left;'><a href='". $daten->spotify ."'>Listen on Spotify</a><br />";
echo "<div id='element_sep'>-</div>";
echo "<img src='images/servericon.png' style='float:left;'><a href='". $daten->nas ."'>Listen on toegrNAS</a><br />";
echo "<div id='element_sep'>-</div>";
echo "<img src='images/itunesicon.png' style='float:left;'><a href='". $daten->itunes ."'>Listen/Buy on iTunes</a>";
echo "</div></li>";
}
while($daten = $db_erg->fetch_object()) {
ausgabe($daten);
}
?>
</ul>
</div>
<div id="overlay_left">-</div>
<div id="overlay_right">-</div>
</div>
<div id="upcoming_releases" class="animated bounceIn">
<div id="headline">Upcoming Releases</div>
<div class="content">
<div id="release_element">
<?php
require_once ('mysql-config.php');
$db_link = mysqli_connect (
MYSQL_HOST,
MYSQL_BENUTZER,
MYSQL_KENNWORT,
MYSQL_DATENBANK
);
$sql = "SELECT date, artist, releasename, itunes, ical, directdl FROM upcoming ORDER BY id DESC LIMIT 40";
$db_erg = $db_link->query( $sql );
function ausgabe($daten) {
echo "<img src='images/icon_cd.png'>";
echo "<span class='release_bold'>". $daten->date .": ". $daten->artist ." - ". $daten->releasename ."</span><br />";
echo "<span class='release_grey'><a href='". $daten->itunes ."'>iTunes (Pre-Order)</a> - <a href='". $daten->ical ."'>Create iCal-Event</a> - <a href='". $daten->directdl ."'>Download</a></span><br />";
}
while($daten = $db_erg->fetch_object()) {
ausgabe($daten);
}
?>
当我尝试嵌入其他两个表格时,页面只显示白色屏幕。问题是,如何通过php在不同位置嵌入三个不同的mysql表?
由于
答案 0 :(得分:0)
这应该在文件的开头,而不是在第三种情况下。
require_once ('mysql-config.php');
$db_link = mysqli_connect (
MYSQL_HOST,
MYSQL_BENUTZER,
MYSQL_KENNWORT,
MYSQL_DATENBANK
);
否则$ db_link未定义,并且在未定义的对象上调用以下方法时会出错。您什么也看不见的原因可能是因为您的网络服务器错误消息已被禁用。
$db_link->query( $sql );
您还可以定义功能3次。你必须使用不同的名字。
function ausgabe($daten)