如何在PHP中创建页面的动态链接?

时间:2014-01-18 09:10:34

标签: php mysql

我正在编写一个代码来创建来自

的cinematics-play-trailers.php视频页面的链接

原始链接文件cinematics.php。这是代码:

<?php
$mysqli = mysqli_connect("localhost", "root", "ecncyogclone2012", "4cytedb");

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
} 
else {
    $sql = "SELECT * FROM cinematable ORDER BY id DESC LIMIT 0,5";
    $res = mysqli_query($mysqli, $sql);


    if ($res) {
        while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
            $id  = $newArray['id'];
            $dateField = $newArray['cinemaDateCreat'];
            $titleField = $newArray['cinemaTitle'];
            $descField = $newArray['cinemaDesc'];
            $imgField = $newArray['cinemaImg'];
            $linkField = $newArray['cinemaLink'];
            $display_block = "<img src=\"media/picture/".$imgField."\" width=

\"150\" height=\"120\" alt=\"image\" />";

                        //this next line is where I get an error

            echo "<a href=\"cinematics-play-trailers.php?video=".$id

['video'].">".$display_block."</a>";

            }
    } 

else {
        printf("Could not retrieve records: %s\n", mysqli_error($mysqli));
    }

    mysqli_free_result($res);
    mysqli_close($mysqli);
}
?>

这就是我在cinematics-play-trailers.php页面上的内容:

<?php 

   if(isset($_GET['video']))
   {
    $curr_vid_id = $_GET['video'];

    $mysqli = mysqli_connect("localhost", "root", "ecncyogclone2012", "4cytedb");

    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    } 
    else {
        $sql = "SELECT * FROM cinematable ORDER BY id WHERE id = $curr_vid_id ";
        $res = mysqli_query($mysqli, $sql);


        if ($res) {
            while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
                $id  = $newArray['id'];
                $dateField = $newArray['cinemaDateCreat'];
                $titleField = $newArray['cinemaTitle'];
                $descField = $newArray['cinemaDesc'];
                $imgField = $newArray['cinemaImg'];
                $linkField = $newArray['cinemaLink'];

            echo
            "<video src=\"media/$linkField\" Controls width=\"690\"  ></video>
            <br>
            <a href=\"media/$linkField\"><img name=\"download_this_file\" 

src=\"images/download_this_file.gif\" width=\"165\" height=\"50\"></a>
            <a href=\"http://www.youtube.com/4cyteworld\"><img src=

\"images/play_on_youtube.fw.png\" width=\"114\" height=\"50\"></a>";


                }
        } 

    else {
            printf("Could not retrieve records: %s\n", mysqli_error($mysqli));
        }

        mysqli_free_result($res);
        mysqli_close($mysqli);
        }
   }
    else    {
            echo "Cant display Video Now !";

            }  

   ?>

我需要获得正确的代码。

1 个答案:

答案 0 :(得分:1)

你不要在这里关闭href属性的引号:

echo "<a href=\"cinematics-play-trailers.php?video=".$id['video'].">".$display_block."</a>";

像这样编辑:

echo "<a href=\"cinematics-play-trailers.php?video=".$id['video']."\" >".$display_block."</a>";