我正在嘗試更新從MySQL到PDO的主/從設置以便與PHP7兼容。我已經準備好了母版頁 - 它會生成一個列出音頻文件的表格,當您點擊一個標題時,您的想法是,您將進入顯示音頻播放器的詳細信息頁面。我在編寫詳細信息頁面時遇到問題,因此來自主頁面的ID會傳遞到詳細信息頁面,並顯示標題和作者以及HTML5音頻播放器。傳遞PDO的詳細信息頁的行ID
這裏是母版頁的代碼:
<?php
$doc->addScript(JURI::root(true).'/templates/nfhop/js/sorttable.js')
?>
<?php
require_once JPATH_SITE.'/includes/dbAudio.php'; ?>
<?php $query = $handler->query('SELECT * from audio ORDER BY subject ASC'); ?>
<article class="left">
<div class="formwrap">
<table class="members-audiolist table-striped sortable" border="0" align="left">
<thead>
<tr class="audio_header">
<td><p class="house-red">Subject</p></td>
<td><p class="house-red">Title</p></td>
<td><p class="house-red">Author</p></td>
</tr>
</thead>
<?php
while($r = $query->fetch(PDO::FETCH_OBJ)) { ?>
<tbody>
<tr>
<td width="25%"><?php echo $r->subject; ?></td>
<td><a href="index.php/audioplayer-pdo?recordID=<?php echo $r->id; ?>"> <?php echo $r->title; ?></a></td>
<td><?php echo $r->author; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="clearfix"></div>
</div>
<div style="margin-left:18px">
<p style="margin-top: 8px; font-size: 1em">To listen: click on title</p>
<p style="font-size: 1em">To download: right click on title and select save link as...</p>
<p style="font-size: 1em">You can sort by subject, title or author, just click on heading at top of column</p>
</div>
</article>
這是我的代碼試圖在詳細資料頁:
<?php
require_once JPATH_SITE.'/includes/dbAudio.php';
$query = $handler->query('SELECT * FROM audio WHERE id = ?'); ?>
?>
<hr class="divider" />
<h2><?php echo $r->title; ?> </h2>
<p>Speaker: <?php echo $r->author; ?> </p>
<p><?php echo $r->date; ?> </p>
<p><span style="font-style: italic">Category: <?php echo $r->subject; ?> </p><br />
<audio controls>
<source src="http://media.nfhop.org/<?php echo $r->audio_location; ?>" type="audio/mp3">
</audio>
<p class="margin-T10"><a href="http://www.nfhop.org/<?php echo $r->notes_location; ?>"> <img src="http://www.nfhop.org/<?php echo $r->image; ?>"></a></p>
<p><a href="/index.php/resources/audio">return to audio list</a>
將是在得到這個工作的任何援助表示感謝!
'$ handler'是什麼?你如何定義它? –
$ handler = new PDO - 用於訪問數據庫文件的參數 – nfhopmike