這是我的分頁腳本:外鍵和分頁
<?php
/***********************************
* PhpMyCoder Paginator *
* Created By PhpMyCoder *
* 2010 PhpMyCoder *
* ------------------------------- *
* You may use this code as long *
* as this notice stays intact and *
* the proper credit is given to *
* the author. *
***********************************/
?>
<head>
<title> Pagination Test - Created By PhpMyCoder</title>
<style type="text/css">
#nav { font: normal 13px/14px Arial, Helvetica, sans-serif; margin: 2px 0; }
#nav a { background: #EEE; border: 1px solid #DDD; color: #000080; padding: 1px 7px; text-decoration: none; }
#nav strong { background: #000080; border: 1px solid #DDD; color: #FFF; font-weight: normal; padding: 1px 7px; }
#nav span { background: #FFF; border: 1px solid #DDD; color: #999; padding: 1px 7px; }
</style>
</head>
<?php
//Require the file that contains the required classes
include("pmcPagination.php");
//PhpMyCoder Paginator
$paginator = new pmcPagination(20, "page");
//Connect to the database
mysql_connect("localhost","root","PASSWORD");
//Select DB
mysql_select_db("tvguide");
//Select only results for today and future
$result = mysql_query("SELECT programme, channel, airdate, expiration, episode, setreminder FROM epdata1 where airdate >= now() order by expiration GROUP BY airdate");
//You can also add reuslts to paginate here
mysql_data_seek($queryresult,0) ;
while($row = mysql_fetch_array($result))
{
$paginator->add(new paginationData($row['programme'],
$row['channel'],
$row['airdate'],
$row['expiration'],
$row['episode'],
$row['setreminder']));
}
?>
<?php
//Show the paginated results
$paginator->paginate();
?><? include("pca-footer1.php"); ?>
<?php
//Show the navigation
$paginator->navigation();
?>
不過,我在這兩個表,它們是epdata1(其中對我的表演豪斯醫生的airtimes是),並housemdep加上setreminder表。
如何使用與此相關的外鍵?我不確定這是否適用於我的劇本,但願意嘗試。
我想什麼做的是從表housemdep 選擇某些事件(的電視劇集),如果任何被選中它們顯示爲這樣:
House M.D. showing on Channel 1 June 6th - 8:00pm "Wilson" Set Reminder
House M.D. showing on Channel 1 June 7th - 1:30am "Wilson" Set Reminder
House M.D. showing on Channel 1 June 7th - 12:55pm "House's Head" Set Reminder
或類似這樣的,如果我沒有選擇該行的一集:
House M.D. showing on Channel 1 June 7th - 8:00pm "House's Head" Set Reminder
House M.D. showing on Channel 1 June 8th - 9:00pm Set Reminder
House M.D. showing on Channel 1 June 9th - 2:30pm Set Reminder
House M.D. showing on Channel 1 June 7th - 8:00pm "Que Sera Sera" Set Reminder
外鍵和鏈接表的關係對我來說是新的,如果任何人都可以幫助我會欣賞這一點。
另外,我試圖讓像這樣我的程序(這是代碼應如何呈現,如果你在瀏覽器上查看源文件點擊):
<tr><td><b><a href="housemd.php">House M.D.</a></b></td><td>showing on <a href="channel/1"><i>Channel 1</i></a></td><td>June 9th - 7:00pm</td><td><b>"<a href="episodes/714790">House's Head</a>"</b></td><td><img src="reminder.gif" height="16" width="22"> <a href="reminder.php" alt="Set a reminder" target="_top">Set Reminder</a></td></tr>
豪斯醫生顯示在頻道1 6月10日 - 上午12時25 「房子的頭」設置提醒 豪斯醫生顯示在頻道1 6月10日 - 下午12:55 設置提醒 豪斯醫生顯示在頻道1 6月10日 - 下午9:00 「威爾遜」設置提醒 豪斯醫生顯示在頻道1 6月11日 - 凌晨1:30 「威爾遜」設置提醒 樓MD顯示在頻道1 6月11日 - 下午8:00 「生活的夢想」設置提醒 豪斯醫生顯示在頻道1 6月12日 - 下午7:00 集合R eminder
我已經嘗試了一些Google在這個腳本的另一個版本(這是運行Apache和PHP 5.28/MySQL的本地主機服務器上的原始克隆)的外鍵上建議的內容,但我不確定如何執行這個。
謝謝。
你有什麼麻煩?數據庫查詢是否需要通過外鍵將表連接起來?如果沒有,那麼將表格連接起來,看看你的分頁功能。最好的學習方法是嘗試。修改來修復。 此外,這不是分頁查詢的最佳方式。如果您的查詢具有10k條結果,它將緩存所有這些結果,然後您從10k的緩衝列表中只使用20條(或每頁值)。通常最好使用mysql關鍵字LIMIT來讓查詢只返回所需的行數。 – 2010-06-07 06:20:21
我無法使用通過外鍵將表連接在一起的數據庫查詢,這是它的要點。 至於我的分頁腳本,每個腳本顯示20行,這是一個免費的腳本,我正在使用;) – whitstone86 2010-06-07 08:56:21