2014-05-05 65 views
0

我認爲問題標題不太準確,但這裏是我正面臨的問題的詳細信息。 我有電影數據庫在Oracle10g 我已經包括一個選項供用戶在數據庫中按標題搜索電影。 我用這一段代碼顯示Retured行...從數據庫中獲取行並將它們鏈接到其他頁面

<h1>Search Results</h1> 
<table border = "1px"> 
<thead> 
<tr> 
    <th>ID</th> 
    <th>RATING</th> 
    <th>Title</th> 
    <th>Description</th> 
    <th>Category</th> 
    <td>Duration</td> 
    <td>Actor</td> 
</tr> 
</thead> 
<tbody> 
<?php 
$search = $_POST['search']; 
$search = sanitize($search); 
$search = '%'.$search.'%'; 
$conn = oci_connect("asim","asim","localhost/xe"); 
$stid = oci_parse($conn,"SELECT 
       film.film_id AS FID, 
       film.title AS title, 
       film.description AS description, 
       category.name AS category, 
       film.duration AS length, 
       film.rating AS rating, 
       CONCAT (actor.first_name ,CONCAT(' ', actor.last_name)) AS actors 
       FROM category 
       LEFT JOIN film_category ON category.category_id = film_category.category_id 
        LEFT JOIN film ON film_category.film_id = film.film_id 
        JOIN film_actor ON film.film_id = film_actor.film_id 
        JOIN actor ON film_actor.actor_id = actor.actor_id 
       WHERE title LIKE '".$search."'"); 
    oci_execute($stid); 
    while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) { 
     print "<tr>\n"; 
    foreach ($row as $item) { 
     print " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n"; 
    } 
      print "</tr>\n"; 
    } 
?> 
</tbody> 
</table> 

我正在以表格形式顯示的結果! 現在我想要的是讓每部電影的標題或film_id都被鏈接起來。 ,並且點擊時它應該導航到該電影的特定頁面。 該頁面可能類似於index.php?id = 1337 並且在索引頁面$ _GET ['userid']可用於獲取關於該電影的信息 主要問題是製作film_id或標題或整個排一個鏈接 我試過使用標籤,但沒有成功。 我是PHP和oracle的新手。 任何形式的幫助將不勝感激。

+0

更新了我的答案,以包含錨鏈接生成示例。 –

回答

0

如果檢查出oci_fetch_array的文檔中發現here你會看到,因爲你使用的OCI_ASSOC參數,您可以訪問使用其命名鍵的結果。

在你內部while循環中,您應該能夠使用您在Oracle SELECT查詢FID中指定的列名訪問film_id。

$row['FID'] 

然後,您可以使用html anchor tag<a>生成一個鏈接到。

print '<a href="index.php?id=' . $row['FID'] . '">link text</a>'; 

類似的東西來,這是考慮到所有這些,我有一個例子,你可以試試下面會告訴你如上面提到的如何訪問數據,你應該能夠從那裏繼續。

while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) { 
    print $row['PID'] . '<br />'; 
} 
+0

如何在此聲明中將數組elemnt包裝在錨標記中? ($ row = oci_fetch_array($ stid,OCI_ASSOC + OCI_RETURN_NULLS))print $ row ['PID']。 '
'; }其次,我怎樣才能做一個鏈接,如 「href =」index.php $ row ['FILM_ID']「」 –

+0

當你建立你的錨鏈接,你可以連接你的'print'語句的php和html你一直在使用連接'''運算符。所以'打印'link text';' –

相關問題