Hey everyone, I've always trusted this site to help me with my occasional PHP problems and I was wondering if it would be as helpful today. I have written a simple PHP pagination script that uses a Javascript code to do all of the Pagination work. The two functions that are at work here work to create a pagination system. The problem arises on occasion when a query is sent (example), the script will return that there is 100 results, but it will only show 99 of them, this throws the rest of the layout off. I have looked through the javascript and it is solid, the problem appears to be with the PHP code, My only guess is that it's not accurately determining when the end of the array truly is, and it's creating an issue. It should be noted that this pagination script doesn't error all the time, just on occasion.
function fetch_data($query, $row_count)
{
$All_Pages = array();
$Select_All = sql::s_query($query);
$x=1;
while($row = mysql_fetch_array($Select_All))
{
$x++;
if($x == $row_count)
{
$x=0;
$All_Pages[] = '<li class="last"><a href="item_select.php?Item_ID='.$row['id'].'"><img src="./Uploads/IMG/'.$row['avatar'].'.png" alt="" /></a><b>'.sql::d_filter($row['title']).'</b><p><span>'.sql::d_filter(paginate::paginate_convert_owner($row['owner'])).'</span>$'.$row['price'].'</p></li>';
}else{
$All_Pages[] = '<li><a href="item_select.php?Item_ID='.$row['id'].'"><img src="./Uploads/IMG/'.$row['avatar'].'.png" alt="" /></a><b>'.sql::d_filter($row['title']).'</b><p><span>'.sql::d_filter(paginate::paginate_convert_owner($row['owner'])).'</span>$'.$row['price'].'</p></li>';
}
}
return $All_Pages;
}
function paginate_convert_owner($owner)
{
$owner = sql::s_filter($owner);
$SQL = "SELECT * FROM STORE WHERE OWNER = '$owner'";
$result = sql::s_object($SQL, "Name");
return $result;
}
function paginate_results($array, $start_count, $end_count)
{
$counter = 0;
foreach($array as $pages)
{
if(count($array) == 1) //if only one result echo all data
{
echo '<div class="result"><ul>';
echo $pages;
echo "</li></ul></div></div></div>";
break;
}
if($pages == end($array))
{
echo $pages;
echo "</li></ul></div></div></div>";
break;
}
if($counter == $start_count)
{
echo '<div class="result"><ul>';
}
$counter++;
echo $pages;
if($counter == $end_count)
{
echo "</li></ul></div>";
$counter = $start_count;
}
}
}