我的主页列表中有20行来自我的数据库,现在我想创建另一个页面,当从主页单击链接时,将显示一条记录的完整详细信息,这是我的代码,显示20条记录:< / p>
<table class="table stats-table ">
<thead>
<tr>
<th colspan="3">Latest Uploads</th>
</tr>
</thead>
<tbody>
<?php
require_once 'dbconfig.php';
$query = "SELECT musicID, musicName, musicUploader, musicDate FROM tbl_music ORDER BY musicDate DESC LIMIT 20";
$stmt = $DBcon->prepare( $query );
$stmt->execute();
while ($row=$stmt->fetch(PDO::FETCH_ASSOC) ) {
extract($row);
?>
<tr>
<td><?php echo $musicName; ?></td>
<td align="center"><span class="label label-success"><em><b>By:</b> <?php echo $musicUploader; ?></em></span> — <?php echo $musicDate; ?></td>
<td><h5><a href="music-details.php?music=<?php echo $musicID; ?>"><i class="fa fa-download"></i></a></h5></td>
</tr>
<?php
}
?>
</tbody>
</table>
所以请不要知道该怎么做 music-details.php 我需要帮助的页面。
提前致谢
答案 0 :(得分:0)
fn2
答案 1 :(得分:0)
我找到了这个问题的工作答案,它确实解决了我的新代码问题:
<?php
$mysql_hostname = 'sql106.epizy.com';
$mysql_username = 'epiz_21612479';
$mysql_password = 'HPpc47590656';
$mysql_dbname = 'epiz_21612479_db';
$music = $_GET['music'];
try {
$pdo= new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
exit( $e->getMessage() );
}
try {
$stmt = $pdo->prepare('SELECT * FROM tbl_music WHERE musicID = :id');
$stmt->bindParam(':id', $music);
$stmt->execute();
} catch (PDOException $e) {
echo $e->getMessage();
}
/* optional method
foreach($stmt as $row) {
echo $row['id'] . ' ' . $row['name'] . ' ' . $row['email'];
}
*/
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$id = $row['musicID'];
$mn = $row['musicName'];
$ma = $row['musicArtist'];
$mu = $row['musicUploader'];
$mf = $row['musicFile'];
$ms = $row['musicSize'];
$md = $row['musicDate'];
}
?>
以下是详细信息的显示位置:
艺术家:
<p><b>Uploader:</b> <?php echo $mu; ?></p>
<p><b>Size:</b> <?php echo $ms; ?></p>
<p><b>Date Uploaded:</b> <?php echo $md; ?></p>
<a href="downloads/<?php echo $mf; ?>" title="Downloadnow" class='btn btn-sm btn-danger'><i class="fa fa-cloud-download"></i> Download </a>
感谢所有试图帮助我的人,我也从stackoverflow得到了答案 答案在这里How to retrieve details for a particular id from MYSQL database