从数据库中获取行并将其链接到其他页面

时间:2014-05-05 00:02:42

标签: php html database hyperlink oracle10g

我认为问题标题不是那么准确,但这里是我所面临的问题的细节。 我在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>

我得到的结果以表格形式显示! 现在我想要的是让每部电影的标题或电影内容成为一个链接。 单击时,它应导航到该电影的特定页面。 该页面可能类似于 index.php?id = 1337 在索引页面上,$ _GET ['userid']可用于获取有关该电影的信息 主要问题是使film_id或title或整行成为链接 我尝试使用标签,但没有成功。 我是PHP和oracle的新手。 任何形式的帮助都将非常感激。

1 个答案:

答案 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 />';
}