Jump to content

[SOLVED] problem with pagination


uwannadonkey

Recommended Posts

???

 

i found this code on one of the topics

i think its guilty's

<?php
include('inc/header.php');
$con = mysql_connect("localhost","donkey9_Admin","***");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("donkey9_Game", $con);

$page_num = $_GET['page'];
if(empty($page_num))
{
$page_num = 1;
}
$ppp = 5; //posts per page
$min_ppp = ($ppp*$page_num)-$ppp;
$query = mysql_query("SELECT * FROM users") or die(mysql_error());
$num_rows = mysql_num_rows($query);
$query = mysql_query("SELECT * FROM users ORDER BY 
level LIMIT $min_ppp, $ppp") or die(mysql_error());
$rows = mysql_num_rows($query);
$pages = ceil($num_rows/$ppp);

while($row = mysql_fetch_array($query))
{
$first_name = $row['ID'];
$last_name = $row['display_name'];
$points = $row['level'];
$tutor = $row['gold'];


echo "<table><tr><td>$first_name $last_name</td><td>$tutor</td>/<td>$points<td/></tr></table>";
}

if($page_num == 1)
{
echo "Prev ";
} else
{
	$prev_page = $page_num-1;
	echo "<a href=\"{$PHP_SELF}?page={$prev_page}\">Prev</a>";
}
for($i = 1; $i <= $pages; $i++)
{
if($i == 1)
{
	echo " ";
}
if($i == $page_num)
{
	echo $i;
} else
	{
		echo "<a href=\"{$PHP_SELF}?page={$i}\">{$i}</a>";
	}
if($i != $pages)
{
	echo ", ";
} else
	{
		echo " ";
	}
}
if($page_num == $pages)
{
echo "Next";
} else
{
	$next_page = $page_num+1;
	echo "<a href=\"{$PHP_SELF}?page={$next_page}\">Next</a>";
}
mysql_close($con)





?>

 

well i was editing it, i wanna turn it into a ranking page for my game, but when i try to do that, this happens:

 

/

4 dime 0 1

/

5 tommy 0 1

/

6 The Prophet 71 1

/

7 D4rksorrow 500 1

/

12 Dracor 338 1

 

where do the slashes come from? and how do i make them all lined up in a table? i tried to do it, but its not working?

Link to comment
https://forums.phpfreaks.com/topic/64919-solved-problem-with-pagination/
Share on other sites

while($row = mysql_fetch_array($query))
{
$first_name = $row['ID'];
$last_name = $row['display_name'];
$points = $row['level'];
$tutor = $row['gold'];


echo "<table><tr><td>$first_name $last_name</td><td>$tutor</td>/<td>$points<td/></tr></table>";
}

 

The key is right here in this block of code. Notice, your in a while loop, so your creating whole new tables for this text, the slash comes from between $tutor</td> / <td>$points

 

Try this.

 

 

<table>
<?php
while($row = mysql_fetch_array($query))
{
$first_name = $row['ID'];
$last_name = $row['display_name'];
$points = $row['level'];
$tutor = $row['gold'];

echo "<tr><td>$first_name $last_name</td><td>$tutor</td><td>$points<td/></tr>";

}
?>
</table>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.