1

Hi I wrote code for load 5 elements from database on 1 page but it's show me a notice Notice: Undefined index: recordstart

Here is my code

   <?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);
                }
?>

I can't solve my problem with another answers!!!

CroStorm99
  • 154
  • 1
  • 3
  • 11

1 Answers1

2

You don't need this line.

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

You're checking and setting it already here

$recordstart = (int)(isset($_GET['recordstart'])) ? $_GET['recordstart'] : 0;
user3783243
  • 5,368
  • 5
  • 22
  • 41
  • but it's show me same notice again – CroStorm99 Apr 03 '15 at 21:05
  • You removed the line I stated wasn't needed and it still said `undefined index`? – user3783243 Apr 03 '15 at 21:07
  • Oh, one sec missed one thing updating... – user3783243 Apr 03 '15 at 21:07
  • oh sorry it says variable not index – CroStorm99 Apr 03 '15 at 21:08
  • Okay, should be all set now, see update. Sorry missed you were using variable, not `$_GET` on second line . – user3783243 Apr 03 '15 at 21:09
  • You also may want to do a `is_numeric` check on the `recordstart` GET because as is if it isn't a number it will be empty. – user3783243 Apr 03 '15 at 21:10
  • now it's good thanks, but now show me another error Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given – CroStorm99 Apr 03 '15 at 21:11
  • See this thread for that error, http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-or-mysqli-result-boole This thread is resolved though now, I think. – user3783243 Apr 03 '15 at 21:16
  • I already checked that...and when I am on main page it's alright but when I press second page it shows me – CroStorm99 Apr 03 '15 at 21:20
  • Check the values on the second page. Check what the query gives you back from the DB when you execute it there (if anything). Debug a bit, go step by step until you find the issue; or POST the simplest case to reproduce and post that with values. This should be a separate thread though as this is a separate issue. – user3783243 Apr 03 '15 at 21:37