Forum Moderators: coopster

Message Too Old, No Replies

Simple select statement causing me problems

         

dkin

9:54 pm on Jan 19, 2005 (gmt 0)

10+ Year Member



This is the select statement

$query_list = "SELECT * FROM user_char order by rank * 1 asc where rank >= $row[rank]";

for some reason that will not work. Im not sure why. Can you use >= in a select statment?

anyhow, the reason I have it like this is for pagination, I would like to display the user first and then the users with a lesser rank in order, but I do not want to have problems when another page is clicked, Im not sure if this will interfere or not. anyhow help would be appreciated.

Timotheos

11:02 pm on Jan 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi dkin,

You just have to get things in the right order

$query_list = "SELECT * FROM user_char where rank >= $row[rank] order by rank * 1 asc"

Tim

dkin

11:28 pm on Jan 19, 2005 (gmt 0)

10+ Year Member



it is still not working how I would like it to.

Maybe someone can suggest some code, I would like to display the logged in user at the top of the page, then the users with a lower rank below him, but there will be many many users above and below his rank, so I would still like to be able to use NEXT and PREVIOUS links to display users much higher and lower than the logged on user.

if anyone knows how I can do this please let me know.

Timotheos

11:51 pm on Jan 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What you're wanting to do is refered to as pagination. Typically it uses the LIMIT clause in the SQL statement. See this thread for more info on how to do it.
[webmasterworld.com...]

dkin

1:05 am on Jan 20, 2005 (gmt 0)

10+ Year Member



This is the code so far.

<?
/* Set current, prev and next page */
$page = (!isset($_GET['page']))? 1 : $_GET['page'];
$prev = ($page - 1);
$next = ($page + 1);

/* Max results per page */
$max_results = 5;

/* Calculate the offset */
$from = (($page * $max_results) - $max_results);

/* Query the db for total results. You need to edit the sql to fit your needs */
$result = mysql_query("select * from user_char");

$total_results = mysql_num_rows($result);

$total_pages = ceil($total_results / $max_results);

$pagination = '';

/* Create a PREV link if there is one */
if($page > 1)
{
$pagination .= '<a href="page4.php?page='.$prev.'">Previous</a> ';
}

/* Loop through the total pages */
for($i = 1; $i <= $total_pages; $i++)
{
if(($page) == $i)
{
$pagination .= $i;
}
else
{
$pagination .= '<a href="page4.php?page='.$i.'">$i</a>';
}
}

/* Print NEXT link if there is one */
if($page < $total_pages)
{
$pagination .= '<a href="page4.php?page='.$next.'">Next</a>";
}

/* Now we have our pagination links in a variable($pagination) ready to print to the page. I pu it in a variable because you may want to show them at the top and bottom of the page */

/* Below is how you query the db for ONLY the results for the current page */
$result = mysql_query("select * from user_char LIMIT $from, $max_results ");

while ($row = mysql_fetch_array($result))
{

echo $row[rank];
/* This is where you print your current results to the page */
}

?>

I am getting this error

Parse error: parse error, unexpected $ in /home/acewebde/public_html/game/page4.php on line 60

which is this line,?>

now I do not understand why I am getting that error.

Timotheos

5:10 am on Jan 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This line needs a single quote at the end.
$pagination .= '<a href="page4.php?page='.$next.'">Next</a>";

Like this...
$pagination .= '<a href="page4.php?page='.$next.'">Next</a>';