gpt4 book ai didi

php - 三个 MySQL 请求与 php 位于一个文件的不同位置

转载 作者:行者123 更新时间:2023-11-30 01:08:03 25 4
gpt4 key购买 nike

我的 MySQL 数据库中有 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 .":&nbsp;". $daten->artist ."&nbsp;-&nbsp;". $daten->releasename ."</span><br />";
echo "<span class='release_grey'><a href='". $daten->itunes ."'>iTunes (Pre-Order)</a>&nbsp;-&nbsp;<a href='". $daten->ical ."'>Create iCal-Event</a>&nbsp;-&nbsp;<a href='". $daten->directdl ."'>Download</a></span><br />";
}

while($daten = $db_erg->fetch_object()) {
ausgabe($daten);
}

?>

当我尝试嵌入其他两个表时,页面仅显示白屏。问题是,如何通过php在不同位置嵌入三个不同的mysql表?

谢谢

项目链接:http://toegraphics.de/music/

最佳答案

这应该位于文件的开头,而不是第三种情况。

require_once ('mysql-config.php');

$db_link = mysqli_connect (
MYSQL_HOST,
MYSQL_BENUTZER,
MYSQL_KENNWORT,
MYSQL_DATENBANK
);

否则 $db_link 未定义,并且在 undefined object 上调用以下方法时会出错。您看不到任何内容的原因可能是因为您的网络服务器错误消息被禁用。

$db_link->query( $sql );

您还定义了 3 次函数。您必须使用不同的名称。

function ausgabe($daten)

关于php - 三个 MySQL 请求与 php 位于一个文件的不同位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19622525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com