2011-03-19 17 views
0

我想我的網頁看起來像這樣:http://1x.com/photos/latest-additions/如何使用分頁創建'圖片庫'?

我幾乎鏡像它只使用PHP(代碼見下文)。然而,我決定我需要有一個數據庫,因爲從stackoverflow的人告訴我我需要,因爲從長遠來看它會很好。無論如何,所以現在我不知所措,在學習MySQL。我想讓我的頁面與1x頁面非常相似:以特定順序的可點擊圖片(除了我想使用列表而不是表格以獲得更好的Web語義外)以及分頁。有人可以告訴我怎麼能做到這一點?我不打算成爲一名程序員,我只是想知道如何製作佈局+分頁:[

有人可以請幫忙嗎? (通過給我一個劇本,或者告訴我該怎麼做)

哦,

這是我原來的代碼。你可以跳過這個,沒有必要。

<?php 
$rows_per_page = 2; 
$cols_per_page = 2; 
$image_href = '<a href=/'; 
$image_links = array('comics/randy>', 'otherstuff/randy>', 'otherstuff/randy>', 'otherstuff/randy>', 'otherstuff/randy>', 'otherstuff/randy>', 'otherstuff/randy>', 'otherstuff/randy>', 'otherstuff/randy>'); 
$img_srcs = '<img src="https://s3.amazonaws.com/imagetitle/'; 
$images = array(); 

for($i = 1; $i < 10; $i++) 
{ 
    $images[$i] = $i; 
} 
$image_ending = '.png" height="200" width="200" /></a>'; 
$image_break = '<br /><div class="timeago"><div id="submitted">submitted&nbsp;</div>'; 
$image_descriptions = array('<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>', '<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>', '<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>', '<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>', '<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>', '<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>', '<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>', '<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>', '<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>'); 
$total_images = count($images); 
$images_per_page = $rows_per_page * $cols_per_page; 
$total_images = count($images); 
$total_pages = ceil($total_images/$images_per_page); 
$current_page = (int) $_GET['page']; 
if($current_page<1 || $current_page>$total_pages) 
{ 
    $current_page = 1; 
} 

//Get records for the current page 
$page_image_links = array_splice($image_links, ($current_page-1)*$images_per_page, $images_per_page); 
$page_images = array_splice($images, ($current_page-1)*$images_per_page, $images_per_page); 
$page_image_descriptions = array_splice($image_descriptions, ($current_page-1)*$images_per_page, $images_per_page); 
$slots = "<table border=\"0\">"; 
for($row=0; $row<$rows_per_page; $row++) 
{ 
    $slots .= "<tr>"; 
    for($col=0; $col<$cols_per_page; $col++) 
    { 
     $imgIdx = ($row * $rows_per_page) + $col; 
     $img = (isset($page_images[$imgIdx])) ? "{$image_href}{$page_image_links[$imgIdx]}{$img_srcs}{$page_images[$imgIdx]}{$image_ending}{$image_break}{$page_image_descriptions[$imgIdx]}" : '&nbsp;'; 
     $slots .= "<td class='tables'>$img</td>"; 
    } 
    $slots .= "</tr>"; 
} 
$slots .= "</table>"; 

//Create pagination links 
$first = "First"; 
$prev = "Prev"; 
$next = "Next"; 
$last = "Last"; 
if($current_page>1) 
{ 
    $prevPage = $current_page - 1; 
    $first = "<a href=\"w4rmoemfdoiemroifmeromfxdnxvl.php?page=1\">First</a>"; 
    $prev = "<a href=\"w4rmoemfdoiemroifmeromfxdnxvl.php?page={$prevPage}\">Prev</a>"; 
} 
if($current_page<$total_pages) 
{ 
    $nextPage = $current_page + 1; 
    $next = "<a href=\"w4rmoemfdoiemroifmeromfxdnxvl.php?page={$nextPage}\">Next</a>"; 
    $last = "<a href=\"w4rmoemfdoiemroifmeromfxdnxvl.php?page={$total_pages}\">Last</a>"; 
} 

?> 
<html> 
<title></title> 
<head><style type="text/css"> 
#submitted {color: #888888; font-family:Verdana, Geneva, sans-serif; font-size: .8em; float:left;} 
.tables {padding-left: 20px; padding-right: 20px;} 
.timeago {color: #888888; font-family:Verdana, Geneva, sans-serif; font-size: .8em; float:right;} 
</style><script src="/static/jquery-1.5.1.js" type="text/javascript"></script> 
<script src="/static/jquery.timeago.js" type="text/javascript"></script> 
<script type="text/javascript"> 
jQuery(document).ready(function() { 
    jQuery("abbr.timeago").timeago(); 
});</script></head> 
<body> 
<h2>Here are the records for page <?php echo $current_page; ?></h2> 
    <ul> 
    <?php echo $slots; ?> 
    </ul> 
Page <?php echo $current_page; ?> of <?php echo $total_pages; ?> 
<br /> 
<?php echo "view more: {$next}"; ?> 
</body> 
</html> 

謝謝!

回答

0

對於不是程序員,你爲什麼要自己編寫代碼(甚至要求某人爲你寫)?
有很多現成的畫廊套房,如Menalto Gallery,Coppermine Galler y等。
那些方式比一些你可以從一個志願者在Stackoverflow得到的素描更專業的代碼。

只需下載自己一個遊戲。我相信它會滿足你的所有需求

+0

事情發送一頁一頁的數據表是,我需要自定義畫廊。我瞭解php如何在我看代碼時工作,但我不能爲我的生活,瞭解如何開始編碼。你知道我的意思?所以,是的,我真的很喜歡從堆疊中尋找草圖,而不是專業製作畫廊。 – user657847 2011-03-19 23:26:31

+0

@ user657847你知道,你可以自定義這些畫廊。 – 2011-03-19 23:31:19

+0

那麼,你能告訴我,如果很容易創建一個圖片庫?如果我能夠很好地估計到達這一點需要多長時間,我願意學習。 – user657847 2011-03-19 23:35:22

1

如果你絕對想自己做這個是合理的,因爲它可以讓你學習新東西,尋找資源:
1.連接到mysql數據庫從PHP
2.獲取數據從數據庫到一些變量
3.使用查詢字符串
4.崗位,並得到
的先進的東西學習發送異步調用和AJAX