php / mysql脚本中未定义的索引

时间:2015-04-03 20:41:33

标签: php mysql database

您好,我在1页的数据库中编写了加载5个元素的代码,但是它向我显示了一个通知注意:未定义的索引:recordstart

这是我的代码

   <?php
    include 'php_script/init.php';
    $pagesize = 5;

                $recordstart = (int) $_GET['recordstart'];
                $recordstart = (isset($_GET['recordstart'])) ? $recordstart : 0;


                $sql01 = "SELECT * FROM movies ORDER BY year DESC LIMIT $recordstart, $pagesize";
                $records=mysql_query($sql01);

                $result = mysql_query("SELECT count(id) FROM movies");
                $totalrows = mysql_fetch_row($result);

                while ($movies=mysql_fetch_assoc($records)){
                    echo '<div class="movie_box"><p><div class="news_img"><div class="cover"><img src="'.$movies['cover'].'" width = "183px" height = "271px"/></div><br><button class="trailer_button" type="button">Trailer</button></div><strong><p class="h3"><div class="content">'.$movies['name'].'</p></strong>'.$movies['plot'].'<br><br><strong>Žanr</strong>:'.$movies['genre'].'<br><strong>IMDB ocjena</strong>:'.$movies['IMDBrating'].'<br><strong>Director</strong>:'.$movies['director'].'<br><strong>Glumci</strong>:'.$movies['Starring'].'<br><strong>Ocjena korisnika</strong>:</div><br><div class="trailer">'.$movies['trailer'].'</div><div class="dark"></div></p></div>';
                }

                if ($recordstart > 0){
                    $prev = $recordstart - $pagesize;
                    $url = $_SERVER['PHP_SELF'].'?recordstart=$prev';
                    printf('<a id="prev" href="%s"><<</a>',$url);
                }

                if ($totalrows > ($recordstart + $pagesize)){
                    $next = $recordstart + $pagesize;
                    $url = $_SERVER['PHP_SELF'].'?recordstart=$next';
                    printf('<a id="next" href="%s">>></a>',$url);
                }
?>

我无法用另一个答案解决我的问题!!!

1 个答案:

答案 0 :(得分:1)

你不需要这条线。

$recordstart = (int) $_GET['recordstart'];

您已在此处检查并设置

$recordstart = (int)(isset($_GET['recordstart'])) ? $_GET['recordstart'] : 0;