2015-12-24 71 views
1

我想創建一個網站,顯示圖片和一些關於圖片作爲個人學習項目的信息。我遇到的問題不一定是從sql查詢,但分頁。我通過代碼去了,並意識到它是由$頁面所導致的,並開始$,但我不知道如何解決它 的代碼是分頁和SQL查詢php分頁不顯示sql數據

<?php 
include ('config/db_connect.php'); 

/* this is for the pages counter main */ 

// number of pages 
$per_page =4; 

//query pages 
$pages_query = mysql_query("select count('track_id') from music_db"); 
$pages = ceil(mysql_result($pages_query, 0)/$per_page); 

$page = (isset ($_GET['page'])) ? (int)$_GET['page'] : 1; 
$start = ($page - 1) * $per_page; 

$music_db_query = "select * from music_db limit $start , $per_page"; 

$music_db_execute = mysql_query($music_db_query); 

while($row = mysql_fetch_array($music_db_execute)) { 

echo '<link rel="stylesheet" type="text/css" href="css/music.css">'; 
echo '<div style="background-color:#3a3a3a;">'; 
echo '<div class="medium-12 columns">'; 
echo '<article class="mainholder">'; 
echo '<div class="imageholder"><a href="#"><img src="'.$row['track_art'].'"/></a></div>'; 
echo '<div class="maindetails"><a href="#"><h5 style="color:white;">'.$row['track_title'].': '.$row['track_artist'].'</h5></a></div>'; 

$com = $row['track_comments']; 
$comred =readMoreFunction($com); 


echo '<div class="comments"><a style=" color:white;" href="#"><p>'.$comred .'</p></a></div>'; 
echo '</article>'; 
echo '</div>'; 
echo '</div>'; 
} 

function readMoreFunction($story_desc,$link,$targetFile,$id) { 
//Number of characters to show 
$chars =210; 
$story_desc = substr($story_desc,0,$chars); 
$story_desc = substr($story_desc,0,strrpos($story_desc,' ')); 
$story_desc = $story_desc." <a href='$link?$targetFile=$id'>Read More...</p> </a>"; 
return $story_desc; 
} 


if($pages >= 1) { 
    for($x=1; $x<=$pages; $x++){ 

     echo '<a href ="$page='.$x.'">'.$x.'</a> '; 
    } 
} 


mysql_close(); 

?> 
+0

你得到了什麼? – Phoenix

+0

數據不顯示,但分頁顯示的是鏈接[link](http:// http://learn4max.byethost10.com/index.php?page = music)。請檢查看看 – dziedzorm

回答

0

你的代碼是正確的只是嘗試打印結果。看看你得到

感謝

0

請檢查您設置分頁鏈接:

<?php 
    include ('config/db_connect.php'); 

    /* this is for the pages counter main */ 

    // number of pages 
    $per_page =4; 

    //query pages 
    $pages_query = mysql_query("select count('track_id') from music_db"); 
    $pages = ceil(mysql_result($pages_query, 0)/$per_page); 

    $page = (isset ($_GET['page'])) ? (int)$_GET['page'] : 1; 
    $start = ($page - 1) * $per_page; 

    $music_db_query = "select * from music_db limit $start , $per_page"; 

    $music_db_execute = mysql_query($music_db_query); 

    while($row = mysql_fetch_array($music_db_execute)) { 

    echo '<link rel="stylesheet" type="text/css" href="css/music.css">'; 
    echo '<div style="background-color:#3a3a3a;">'; 
    echo '<div class="medium-12 columns">'; 
    echo '<article class="mainholder">'; 
    echo '<div class="imageholder"><a href="#"><img src="'.$row['track_art'].'"/></a></div>'; 
    echo '<div class="maindetails"><a href="#"><h5 style="color:white;">'.$row['track_title'].': '.$row['track_artist'].'</h5></a></div>'; 

    $com = $row['track_comments']; 
    $comred =readMoreFunction($com); 


    echo '<div class="comments"><a style=" color:white;" href="#"><p>'.$comred .'</p></a></div>'; 
    echo '</article>'; 
    echo '</div>'; 
    echo '</div>'; 
    } 

    function readMoreFunction($story_desc,$link,$targetFile,$id) { 
    //Number of characters to show 
    $chars =210; 
    $story_desc = substr($story_desc,0,$chars); 
    $story_desc = substr($story_desc,0,strrpos($story_desc,' ')); 
    $story_desc = $story_desc." <a href='$link?$targetFile=$id'>Read More...</p> </a>"; 
    return $story_desc; 
    } 


    if($pages >= 1) { 
     for($x=1; $x<=$pages; $x++){ 

      echo '<a href ="?page='.$x.'">'.$x.'</a> '; // Here I have updated file.. 
     } 
    } 


    mysql_close(); 

?> 
+0

這裏是鏈接[鏈接](http:// http://learn4max.byethost10.com/index.php?page =音樂) – dziedzorm

+0

該鏈接無法正常工作。 – Kamal

+0

更正的鏈接[鏈接](http://learn4max.byethost10.com/index.php?page=music) – dziedzorm