I'm writing a complex shoutbox (hybrid of a shoutbox and a forum, if you will), and I'm having a problem with pagination. Before I post the code, let me explain what the problem is. I want to show 10 "shouts" on one page. This page will reside in an iframe, so the user does not have a choice in how many shouts he'll see. As it stands, there are 12 (0-11) shouts in the databse. The first page displayes 11, the second page displays nothing. When I click the "prev" button on page that should display the last shout, I get a white page. I've been wrestling with a bunch of different problems with pagination for a while now, and I need a pair of fresh eyes to look at this code and point out what I did wrong.
Code: Select all
?php
//this page gets all the shouts and throws them to a template which is an iframe within profile.php
session_start();
include_once("functions.php");
include_once("user_class.php");
require("/home/tmeet/public_html/smarty/Smarty.class.php");
//id will have to be passed (get)
$id=$_GET['id'];
$user_profile = new User($id);
//get shoutbox information, this is basically a mysql_query()/mysql_fetch_array() operation that returns a 2D array
/*$shouts => [0] => [shouter] = evilmonkey
[shout] = test shout
[date] = 1124294982
[1] => [shouter] = test_user
[shout] = test shout 2
[date] = 1124295020
that's what that variable holds */
$shouts = $user_profile->sb_get_shouts($id);
//for pagination purposes, find out where to start and where to stop, and whether or not to have next/prev buttons
$info['nextbutton'] = "true";
$info['prevbutton'] = "true";
$start = $_GET['start'];
if (!isset($_GET['start']) || $start == 0) {
$start = 0;
$info['prevbutton'] = "false";
}
if ($start + 10 >= sizeof($shouts)){
$stop = sizeof($shoutbox);
$info['nextbutton'] = "false";
} else {
$stop = $start+10;
}
//the template needs to know where we started to know how to link the next/prev buttons
$info['start'] = $start;
//end pagination
//main loop, controls all output
for ($i=$start; $i<=$stop; $i++){
$shoutbox[$i]['shouter'] = $shouts[$i]['shouter'];
$shoutbox[$i]['shout'] = $shouts[$i]['shout'];
$shoutbox[$i]['date'] = date("M d, Y", $shouts[$i]['date']);
if ($shouts[$i]['shouter']=="Annonymous"){
$shoutbox[$i]['age']="";
$shoutbox[$i]['gender']="";
$shoutbox[$i]['pic']="";
}
else {
$userinfo = sql_pull("SELECT `id`, `age`, `gender` FROM `users` WHERE `username`='".$shouts[$i]['shouter']."'", $user_profile->db);
$shoutbox[$i]['age']=$userinfo[0]['age'];
$shoutbox[$i]['gender']=$userinfo[0]['gender'];
//for a picture, 2 options:
//option 1: a smal pic exists in the tmp folder
if (is_file("tmp/S_".$userinfo[0]['id']."_1.jpg")){
$shoutbox[$i]['pic'] = '<img src = "tmp/S_'.$userinfo[0]['id'].'_1.jpg" border = "0">';
}
//option 2: small pic doesn't exist in the tmp folder: two more options open
else {
$userpic = sql_pull("SELECT `pic1` FROM `prefs` WHERE `id`=".$userinfo[0]['id'], $user_profile->db);
//option 1: user doesn't have a main pic
if ($userpic[0]['pic1']==""){
$shoutbox[$i]['pic']="";
}
//option 2: user has a main pic, but for some reason, it hasn't been resized and saved to the tpm/ folder
//this poor user probably never loaded his profile, or just changed his pic
else {
include_once("savepic.php");
savepic(75, 75, $userpic[0]['pic1'],"S_".$userinfo[0]['id']."_1.jpg");
$shoutbox[$i]['pic'] = '<img src = "tmp/S_'.$userinfo[0]['id'].'_1.jpg" border = "0">';
}
}
}
}
?>Thanks in advance.