aznjayx Posted May 8, 2008 Share Posted May 8, 2008 I'm currently working on the webiste and used the code to switch the website to go to a < table > content section, the first page of the mysql that is taken out shows out but with pagination it doesn't work at all. for example there is a link index.php?page=news and when you click on the link the link doesn't function and gives an error and when i click page 1,2,3 the link doesn't go news?=1 <?php $file = $_GET['page'].'.php'; if (file_exists($file)) { include $file; } elseif ($_GET['page'] == '') { include "test.php"; } else { echo "404 ERROR WE COOL"; } ?> </td> <td class="other"> <font color="white"> <?php $file = $_GET['id'].'.php'; if (file_exists($file)) { include $file; } elseif ($_GET['page'] == '') { include "home.php"; } else { echo "404 ERROR WE COOL"; } ?> this code works if i'm only running files that are in that are upload and doesn't load the data from sql since i have pagination in newsfeed.php, when i click on next it doesn't load the date from the mysql Quote Link to comment Share on other sites More sharing options...
Fadion Posted May 8, 2008 Share Posted May 8, 2008 It looks ok to me. Maybe u have the files in another directory, like "includes", so pls tell us what error are u getting? Quote Link to comment Share on other sites More sharing options...
aznjayx Posted May 8, 2008 Author Share Posted May 8, 2008 It looks ok to me. Maybe u have the files in another directory, like "includes", so pls tell us what error are u getting? The error i'm getting is this "Error, query failed" Quote Link to comment Share on other sites More sharing options...
aznjayx Posted May 8, 2008 Author Share Posted May 8, 2008 http://alltraxx.uni.cc/index2.php, it's okay if I use the include the file, but when i link it like this click index2.php?page=newsfeed it'll say the error, and also when i click on the 2 page it gives and error and doesn't show the data it's suppose to show. Quote Link to comment Share on other sites More sharing options...
tronicsmasta Posted May 8, 2008 Share Posted May 8, 2008 idk if this will help but I use the following code for pagination... /pagination section 1 start // the if below, states that if the variable in the URL named page has a value, $start will be set to it, // otherwise by default it is set to 0, meaning that it will start at the beginning of the table by default. $limit = 5; if (!$_GET['start']){ $start = 0; } else { $start = $_GET['start']; } // this if below checks that the start variable isn’t negative, because if it is, our script will screw up. // If it finds that it is, it redirects to the default page where the start is 0. // pagination section 1 end // Select all information from the comments table $sql = "SELECT * FROM $table WHERE channel = '$channel' ORDER BY date DESC LIMIT $start, $limit"; //create list of results $result = @mysql_query($sql,$connection) or die(mysql_error()); // pagination part 2 start // the set of statements below displays the previous and next page links $next = $start + $limit; $previous = $start - $limit; if ($previous < 0) { // do not display previous } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?start=$previous\"><< Previous</a>"; if ($num_rows == 5) { echo "  --  "; } } // numbers rows to display next link $num_rows = mysql_num_rows($result); if ($num_rows < 5) { // do not display next link } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?start=$next\">Next >></a>"; } // pagination part 2 end if you need help understanding it.. pm me or IM me on AIM... user name here is same on AIM... Q Quote Link to comment Share on other sites More sharing options...
Fadion Posted May 8, 2008 Share Posted May 8, 2008 Your page url variable gets in 1,2 etc as value, but in the code u have: $file = $_GET['page'].'.php'; if (file_exists($file)) { include $file; Are u including files 1.php, 2.php etc, or is it me not understanding this. Quote Link to comment Share on other sites More sharing options...
aznjayx Posted May 8, 2008 Author Share Posted May 8, 2008 this is my paging script // how many rows to show per page $rowsPerPage = 3; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; echo '<table width="400" border="0" cellspacing="0" cellpadding="0">'; $query = "SELECT * FROM news LIMIT $offset, $rowsPerPage"; $result = mysql_query($query) or die('Error, query failed'); $color="1"; // print the random numbers while($row = mysql_fetch_array($result)){ if($color==1){ echo '<tr> <td class="beam">'.$row['date'].' '.$row['time'].' '.$row['name'].'<br>'.$row['msg'].'</td></tr>'; // Set $color==2, for switching to other color $color="2"; } // When $color not equal 1, use this table row color else { echo '<tr> <td class="beamer">'.$row['date'].' '.$row['time'].' '.$row['name'].'<br>'.$row['msg'].'</td></tr>'; // Set $color back to 1 $color="1"; } } echo '<br>'; echo '</table>'; // how many rows we have in database $query = "SELECT COUNT(id) AS numrows FROM news"; $result = mysql_query($query) or die('Error, query failed'); $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); // print the link to access each page $self = $_SERVER['PHP_SELF']; $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?page=$page\">$page</a> "; } } // creating previous and next link // plus the link to go straight to // the first and last page if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; $first = " <a href=\"$self?page=1\">[First Page]</a> "; } else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } // print the navigation link echo $first . $prev . $nav . $next . $last; ?> Quote Link to comment Share on other sites More sharing options...
aznjayx Posted May 8, 2008 Author Share Posted May 8, 2008 my paging script is in another file though it's called newsfeed.php Quote Link to comment Share on other sites More sharing options...
aznjayx Posted May 9, 2008 Author Share Posted May 9, 2008 please help..almost close to finishing the website :-X Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.