Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 12-14-2008, 11:20 PM Separate Pages
Super Talker

Posts: 102
Trades: 0
I want the SQL query to echo like 10-15 lines then have it make another page, how would I go about doing this?

like
Users 10 then the next page would echo 11-20 and ext.

Last edited by Aaron™; 12-14-2008 at 11:23 PM..
Aaron™ is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-14-2008, 11:42 PM Re: Separate Pages
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
PHP Code:
$page $_GET['page']; //assuming the page is passed by url
$offset 5;
$upper $page $offset;
$lower $upper $offset;

$query "SELECT * FROM `table` LIMIT $lower , $upper";
$result mysql_query($query);
while(
$row mysql_fetch_array($resultMYSQL_NUM))
{
     
//echo here

I think that code will give you an off-by-one bug but that's the general idea.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 12-15-2008, 12:04 AM Re: Separate Pages
Super Talker

Posts: 102
Trades: 0
what would be a code to move to the next page?
like <a href="userlist.php?page="thenextpage">bla</a>

edit: never mind I did it.
PHP Code:
<? echo $_GET['p'] + 1?>

Last edited by Aaron™; 12-15-2008 at 12:11 AM..
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 12-15-2008, 04:31 AM Re: Separate Pages
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Quote:
$query = "SELECT * FROM `table` LIMIT $lower , $upper";
Wrong. Syntax for limit in select statements is "limit $from, $count", not "limit $from, $to". So the correct answer is:
Code:
$query = "SELECT * FROM `table` LIMIT $lower , $offset";
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 12-15-2008, 01:43 PM Re: Separate Pages
Super Talker

Posts: 102
Trades: 0
Is there anyway to get rid of the error when the page variable isn't set?
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 12-15-2008, 02:10 PM Re: Separate Pages
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
PHP Code:
if( isset($_GET['page']) )
{
     
$page $_GET['page'];
}
else
{
     
$page 1;

stoot98 is offline
Reply With Quote
View Public Profile
 
Old 12-15-2008, 02:34 PM Re: Separate Pages
Super Talker

Posts: 102
Trades: 0
So how would I use this tho lol, I am still new.

edit:
oh if there is more than 1 pages it will start to echo 25, other than 15. and echos the stuff that should be on the next page on page 2, like say
foo is on page 2 but it should be on page 3, it will echo on both pages.

Last edited by Aaron™; 12-15-2008 at 06:07 PM..
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 12-15-2008, 10:30 PM Re: Separate Pages
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
The process you are looking for is called pagination. You can find great tutorials in a Google search for php examples.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 12-26-2008, 09:45 PM Re: Separate Pages
Super Talker

Posts: 102
Trades: 0
Its use now,

PHP Code:
<?
$page 
$_GET['p']; //assuming the page is passed by url
$offset 25;
$upper $page $offset;
$lower $upper $offset;
$next $_GET['p'] + 1;
$back $_GET['p'] - 1;

    
$result mysql_query("SELECT * FROM users ORDER BY username ASC LIMIT $upper$offset") or die("");  //mysql_error()
    
while($row mysql_fetch_array($result))
    {
        
$uStatus;
            if(
$row['rights'] == 1)
                {
                    if(
returnRights(loggedUser()) >= 2)
                    {
                        
$uStatus "Regular";
                        
$row['username'] = "<b>".$row['username']."</b>";
                    }
                    else
                    {
                        
$uStatus "Regular";
                    }
                }
            else if(
$row['rights'] == 2)
                {
                    
$uStatus "<b><font color=\"darkgreen\">Moderator</font></b>";
                    
$row['username'] = "<b><font color=\"darkgreen\">".$row['username']."</font></b>";
                    
$row['signature'] = "<font color=\"darkgreen\">".$row['signature']."</font>";
            }
            else if(
$row['rights'] == 3)
                {
                    
$uStatus "<b><font color=\"green\">Administrator</font></b>";
                    
$row['username'] = "<b><font color=\"green\">".$row['username']."</font></b>";
                    
$row['signature'] = "<font color=\"green\">".$row['signature']."</font>";
}
            else if(
$row['rights'] >= 4)
                {
                    
$uStatus "<b><font color=\"orange\">Owner</font></b>";
                    
$row['username'] = "<b><font color=\"orange\">".$row['username']."</font></b>";
                    
$row['signature'] = "<font color=\"orange\">".$row['signature']."</font>";
            }

            if(
returnRights(loggedUser()) >= 2)
                {
                    echo 
'<tr>
                            <td><a href="profile.php?uid='
.$row['id'].'" target="_blank">'.$row['username'].'</a></td>
                            <td>'
.$uStatus.'</td>
                            <td>'
.$row['signature'].'</td>
                        </tr>'
;
            }
            else
                {
                    echo 
'<tr>
                            <td>'
.$row['username'].'</td>
                            <td>'
.$uStatus.'</td>
                            <td>'
.$row['signature'].'</td>
                        </tr>'
;
            }
    } 
?>
PHP Code:
<?
if($_GET['p'] == "") { 
    echo 
'<a href="userlist.php?p='.$next.'">Next Page</a>'

else if(
$_GET['p'] == 0) {
    echo 
'<a href="userlist.php?p='.$next.'">Next Page</a>';
}
else if(
$_GET['p'] >= 1) {
    echo 
'<a href="userlist.php?p='.$back.'">Back Page</a> - 
    <a href="userlist.php?p='
.$next.'">Next Page</a></center>'

?>

Last edited by Aaron™; 12-27-2008 at 03:32 AM..
Aaron™ is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Separate Pages
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29175 seconds with 12 queries