最後一個功能 急麻煩高手們解惑討論

edited 七月 2014 in PHP新手區
各位高手好 小弟因為面臨畢業的專題 做了一個 系統搜尋的網頁

已經把資料庫該用的都用好了 搜尋功能也很完整 但是 現在卡在一個地方

這是我學習的目標網站:

http://ndltd.ncl.edu.tw/cgi-bin/gs32/gsweb.cgi/ccd=JO7GL4/search#result

我想要像他這樣 收尋到資料 這樣顯示出來!!! 對 我已經做到這樣的顯示!!

可是 我想問的是 為什麼 他有辦法 點資料的名稱 再做一次超連結進去做這份資料的 完整檔案

是如何連進去抓取該筆資料的

我有想到是否是 顯示頁面的資料 是一個資料庫 點進去的'詳細資訊 又是另一個資料庫

疑惑的是 要如何抓取 跟做超連結 希望有利害的人 可以做個範例檔 讓我有個方向思考 謝謝你們

BY. PHP 完全新手

評論

  • edited 七月 2014
    1.把搜尋結果的標題改為超連結,透過搜尋結果每篇文章的id 帶入到一個顯示完整內容的php.
    程式碼如:
    <a href="full.php?id=<?php echo  row["id"] ?>">[好文]媽~我要畢業了</a>
    

    2.至於full.php 內容就是利該文的id 來做 WHERE 篩選...就可以找到該篇文章的標題內容了 :)
    大概就像
    $id = mysql_real_escape_string($_GET["id"]);
    SELECT `id`, `title`, `content` FROM `news` WHERE `id` = '$id';
    
    後面輸出省略...
  • 所以說 我要再做一個FULL 的網頁摟
  • 我想您還是把你的網頁部分code 貼上來,最起碼有個資料庫欄位.

    不然也不知道怎幫你.
  • <meta http-equiv="Content-Type" content="text/html; charset=Big5" />

    <title>搜尋結果</title>

    <BODY BGCOLOR="#A9F5F2" Background="新資料夾/bg010.gif">

    <form name="form1" method="post" action="">
    <font face="標楷體"><font size="+3"><center>搜尋結果</center></font></font>
    </form>
    <form name="form2" method="post" action="">
    <div align="left">

    <?php
    $a = "0";
    $Key1 = $_GET;
    $Key2 = $_GET;
    $Key3 = $_GET;
    // 預設的頁數
    $currentpage = $_GET;

    $db_link = mysql_connect("localhost", "root", "qclab");
    if (!$db_link)
    echo "連線失敗";

    mysql_select_db("wu");

    mysql_query("SET NAMES Big5");

    // 每頁顯示的列數

    $rowsperpage = 5;


    // 取得當前的頁數,或者顯示預設的頁數

    if (isset($_GET) && is_numeric($_GET)) {

    // 把變量的類型轉換成 int

    $currentpage = (int) $_GET;

    }

    // 根據當前頁數計算名單的起始位置
    $offset = ($currentpage - 1) * $rowsperpage;

    if (($Key1 != "") && ($Key2 != "") && ($Key3 != "")){
    $count_sql = "SELECT count(*) FROM essay WHERE TitleC= '$Key1' AND TitleE like '$Key2' AND Year= '$Key3'";
    $count_result = mysql_query($count_sql);
    $sql = "SELECT * FROM essay WHERE TitleC= '$Key1' AND TitleE like '$Key2' AND Year= '$Key3' LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql);
    }else if (($Key1 != "") && ($Key2 != "") && ($Key3 == "")){
    $count_sql = "SELECT count(*) FROM essay WHERE TitleC LIKE '%$Key1%' AND TitleE LIKE '%$Key2%'";
    $count_result = mysql_query($count_sql);
    $sql = "SELECT * FROM essay WHERE TitleC LIKE '%$Key1%' AND TitleE LIKE '%$Key2%' LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql);
    }else if (($Key1 != "") && ($Key2 == "") && ($Key3 != "")){
    $count_sql = "SELECT count(*) FROM essay WHERE Year = '$Key3' AND TitleC LIKE '%$Key1%'";
    $count_result = mysql_query($count_sql);
    $sql = "SELECT * FROM essay WHERE Year = '$Key3' AND TitleC LIKE '%$Key1%' LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql);
    }
    else if (($Key1 != "") && ($Key2 == "") && ($Key3 == "")){
    $count_sql = "SELECT count(*) FROM essay WHERE TitleC like '%$Key1%'";
    $count_result = mysql_query($count_sql);
    $sql = "SELECT * FROM essay WHERE TitleC like '%$Key1%' LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql);
    }
    else if (($Key1 == "") && ($Key2 != "") && ($Key3 == "")){
    $count_sql = "SELECT count(*) FROM essay WHERE TitleE like '%$Key2%'";
    $count_result = mysql_query($count_sql);
    $sql = "SELECT * FROM essay WHERE TitleE like '%$Key2%' LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql);
    }
    else if (($Key1 == "") && ($Key2 == "") && ($Key3 != "")){
    $count_sql = "SELECT count(*) FROM essay WHERE Year = '$Key3'";
    $count_result = mysql_query($count_sql);
    $sql = "SELECT * FROM essay WHERE Year = '$Key3' LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql);
    }
    else if (($Key1 == "") && ($Key2 != "") && ($Key3 != "")){
    $count_sql = "SELECT count(*) FROM essay WHERE Year = '$Key3'";
    $count_result = mysql_query($count_sql);
    $sql = "SELECT * FROM essay WHERE Year = '$Key3' AND TitleE LIKE '%$Key2%' LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql);
    }
    //else if (($Key1 == "") && ($Key2 == "") && ($Key3 == "")){
    // $result = 2;
    //}

    $r = mysql_fetch_row($count_result);
    $numrows = $r[0];

    // 計算總共需要多少頁
    $totalpages = ceil($numrows / $rowsperpage);
    // 若過當前的頁數大於頁數總數

    if ($currentpage > $totalpages) {

    // 把當前頁數設定為最後一頁

    $currentpage = $totalpages;

    } // end if

    // 若果當前的頁數小於 1

    if ($currentpage < 1) {

    // 把當前頁數設定為 1

    $currentpage = 1;

    } // end if

    if(mysql_num_rows($result) != "0"){
    while($row = mysql_fetch_assoc($result)){

    if ($a != ""){
    $a++;
    }
    echo '<table style="border: 0px double rgb(109, 2, 107); height: 100px; width: 600px;" align="center" cellpadding="2" cellspacing="2" frame=" hsides" rules="none">';
    echo "

    <hr><tr>
    <td><b>".$a."</b></td><td><b>".$row."/".$row."</b></td></tr>
    <tr>
    <td></td><td>".$row."/".$row."/".$row."</td></tr>
    <tr>
    <td></td><td>研究生:".$row."</td></tr></tr>
    <tr>
    <td></td><td>指導教授:".$row."</tr></td>
    <tr>
    <td></td><td>全文下載   <a href='downloadfile.php?file=pdf/01.pdf' target='_blank'><img src='新資料夾/book-open.png' alt='全文下載'></a> </tr></td>
    ";



    }
    }else{
    echo "查無此資料";
    }
    echo "</table>";
    ?>
    </div>


    <?php
    // 若果正在顯示第一頁,無需顯示「前一頁」連結

    if ($currentpage > 1) {

    // 使用 << 連結回到第一頁

    echo " <a href='{$_SERVER}?currentpage=1&Keyin1=$Key1&Keyin2=$Key2&Keyin3=$Key3'><<</a> ";

    // 前一頁的頁數

    $prevpage = $currentpage - 1;

    // 使用 < 連結回到前一頁

    echo " <a href='{$_SERVER}?currentpage=$prevpage&Keyin1=$Key1&Keyin2=$Key2&Keyin3=$Key3'>上一頁</a> ";

    } // end if



    // 顯示的頁數範圍

    $range = 3;

    // 顯示當前分頁鄰近的分頁頁數

    for ($x = (($currentpage - $range) - 1); $x < (($currentpage + $range) + 1); $x++) {

    // 如果這是一個正確的頁數...

    if (($x > 0) && ($x <= $totalpages)) {

    // 如果這一頁等於當前頁數...

    if ($x == $currentpage) {

    // 不使用連結, 但用高亮度顯示

    echo " [<b>$x</b>] ";

    // 如果這一頁不是當前頁數...

    } else {

    // 顯示連結

    echo " <a href='{$_SERVER}?currentpage=$x&Keyin1=$Key1&Keyin2=$Key2&Keyin3=$Key3'>$x</a> ";

    } // end else

    } // end if

    } // end for

    // 如果不是最後一頁, 顯示跳往下一頁及最後一頁的連結

    if ($currentpage != $totalpages) {

    // 下一頁的頁數

    $nextpage = $currentpage + 1;

    // 顯示跳往下一頁的連結

    echo " <a href='{$_SERVER}?currentpage=$nextpage&Keyin1=$Key1&Keyin2=$Key2&Keyin3=$Key3'>下一頁</a> ";

    // 顯示跳往最後一頁的連結

    echo " <a href='{$_SERVER}?currentpage=$totalpages&Keyin1=$Key1&Keyin2=$Key2&Keyin3=$Key3'>>></a> ";

    } // end if
    ?>

    </form>
    </body>
    <a style="text-decoration: none" href="123.php"><b>返回搜尋頁面</b></a>


  • ↑這個是 結果頁面 搜尋結果
  • 搜尋結果



    <?php<br />$a = "0";
    $Key1 = $_GET['Keyin1'];
    $Key2 = $_GET['Keyin2'];
    $Key3 = $_GET['Keyin3'];
    // 預設的頁數
    $currentpage = $_GET['currentpage'];
    
    $db_link = mysql_connect("localhost", "root", "qclab");
    if (!$db_link)
    echo "連線失敗";
    
    mysql_select_db("wu");
    
    mysql_query("SET NAMES Big5");
    
    // 每頁顯示的列數
    
    $rowsperpage = 5;
    
    
    // 取得當前的頁數,或者顯示預設的頁數
    
    if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
    
    // 把變量的類型轉換成 int
    
    $currentpage = (int) $_GET['currentpage'];
    
    }
    
    // 根據當前頁數計算名單的起始位置
    $offset = ($currentpage - 1) * $rowsperpage;
    
    if (($Key1 != "") && ($Key2 != "") && ($Key3 != "")){
    $count_sql = "SELECT count(*) FROM essay WHERE TitleC= '$Key1' AND TitleE like '$Key2' AND Year= '$Key3'";
    $count_result = mysql_query($count_sql);
    $sql = "SELECT * FROM essay WHERE TitleC= '$Key1' AND TitleE like '$Key2' AND Year= '$Key3' LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql);
    }else if (($Key1 != "") && ($Key2 != "") && ($Key3 == "")){
    $count_sql = "SELECT count(*) FROM essay WHERE TitleC LIKE '%$Key1%' AND TitleE LIKE '%$Key2%'";
    $count_result = mysql_query($count_sql);
    $sql = "SELECT * FROM essay WHERE TitleC LIKE '%$Key1%' AND TitleE LIKE '%$Key2%' LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql);
    }else if (($Key1 != "") && ($Key2 == "") && ($Key3 != "")){
    $count_sql = "SELECT count(*) FROM essay WHERE Year = '$Key3' AND TitleC LIKE '%$Key1%'";
    $count_result = mysql_query($count_sql);
    $sql = "SELECT * FROM essay WHERE Year = '$Key3' AND TitleC LIKE '%$Key1%' LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql);
    }
    else if (($Key1 != "") && ($Key2 == "") && ($Key3 == "")){
    $count_sql = "SELECT count(*) FROM essay WHERE TitleC like '%$Key1%'";
    $count_result = mysql_query($count_sql);
    $sql = "SELECT * FROM essay WHERE TitleC like '%$Key1%' LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql);
    }
    else if (($Key1 == "") && ($Key2 != "") && ($Key3 == "")){
    $count_sql = "SELECT count(*) FROM essay WHERE TitleE like '%$Key2%'";
    $count_result = mysql_query($count_sql);
    $sql = "SELECT * FROM essay WHERE TitleE like '%$Key2%' LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql);
    }
    else if (($Key1 == "") && ($Key2 == "") && ($Key3 != "")){
    $count_sql = "SELECT count(*) FROM essay WHERE Year = '$Key3'";
    $count_result = mysql_query($count_sql);
    $sql = "SELECT * FROM essay WHERE Year = '$Key3' LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql);
    }
    else if (($Key1 == "") && ($Key2 != "") && ($Key3 != "")){
    $count_sql = "SELECT count(*) FROM essay WHERE Year = '$Key3'";
    $count_result = mysql_query($count_sql);
    $sql = "SELECT * FROM essay WHERE Year = '$Key3' AND TitleE LIKE '%$Key2%' LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql);
    }
    //else if (($Key1 == "") && ($Key2 == "") && ($Key3 == "")){
    // $result = 2;
    //}
    
    $r = mysql_fetch_row($count_result);
    $numrows = $r[0];
    
    // 計算總共需要多少頁
    $totalpages = ceil($numrows / $rowsperpage);
    // 若過當前的頁數大於頁數總數
    
    if ($currentpage > $totalpages) {
    
    // 把當前頁數設定為最後一頁
    
    $currentpage = $totalpages;
    
    } // end if
    
    // 若果當前的頁數小於 1
    
    if ($currentpage < 1) {
    
    // 把當前頁數設定為 1
    
    $currentpage = 1;
    
    } // end if
    
    if(mysql_num_rows($result) != "0"){
    while($row = mysql_fetch_assoc($result)){
    
    if ($a != ""){
    $a++;
    }
    echo ''; echo " ".$a."".$row['TitleC']."/".$row['TitleE']." ".$row['school']."/".$row['Year']."/".$row['level']." 研究生:".$row['Author']." 指導教授:".$row['Professor']." 全文下載    "; }}else{ echo "查無此資料";}echo "
    ";
    ?>
    
    
    
    <?php<br />// 若果正在顯示第一頁,無需顯示「前一頁」連結
    
    if ($currentpage > 1) {
    
    // 使用 << 連結回到第一頁<br />
    echo " <<</a> ";
    
    // 前一頁的頁數
    
    $prevpage = $currentpage - 1;
    
    // 使用 < 連結回到前一頁
    
    echo " 上一頁 ";
    
    } // end if
    
    
    
    // 顯示的頁數範圍
    
    $range = 3;
    
    // 顯示當前分頁鄰近的分頁頁數
    
    for ($x = (($currentpage - $range) - 1); $x < (($currentpage + $range) + 1); $x++) {
    
    // 如果這是一個正確的頁數...
    
    if (($x > 0) && ($x <= $totalpages)) {<br />
    // 如果這一頁等於當前頁數...
    
    if ($x == $currentpage) {
    
    // 不使用連結, 但用高亮度顯示
    
    echo " [$x] ";
    
    // 如果這一頁不是當前頁數...
    
    } else {
    
    // 顯示連結
    
    echo " $x ";
    
    } // end else
    
    } // end if
    
    } // end for
    
    // 如果不是最後一頁, 顯示跳往下一頁及最後一頁的連結
    
    if ($currentpage != $totalpages) {
    
    // 下一頁的頁數
    
    $nextpage = $currentpage + 1;
    
    // 顯示跳往下一頁的連結
    
    echo " 下一頁 ";
    
    // 顯示跳往最後一頁的連結
    
    echo " >> ";
    
    } // end if
    ?>
    
    
    
    返回搜尋頁面
    
  • edited 八月 2014
    按照你給的資料寫...不過建議你改utf-8

    替換
    echo " ".$a."".$row['TitleC']."/".$row['TitleE']." ".$row['school']."/".$row['Year']."/".$row['level']." 研究生:".$row['Author']." 指導教授:".$row['Professor']." 全文下載 " .   '<a href="full.php?id='. $row['id'] . '">看全文 </a>'; }
    

    full.php
    <?php 
    $username = "root";
    $password = "qclab";
    $hostname = "localhost"; 
    $database = "qclab";
    
    $link = mysql_connect($hostname, $username, $password) ;
    mysql_query("SET NAMES Big5");
    mysql_select_db($database, $link)  or die("error"); 
    $id = $_GET["id"];
    if (isset($id)){
    	$id = mysql_real_escape_string($_GET["id"]);
    
    	$sql  = "select *  from `essay`  WHERE  id='$id'";
    	$result = mysql_query($sql , $link);
    	$row = mysql_fetch_assoc($result);
    	echo $row['text']; // 你的全文欄位 ~ 自己修改
    }
    ?>
    
Sign In or Register to comment.