Results 1 to 2 of 2

Thread: Need help with MySQL / PHP Pagination

  1. #1
    Join Date
    Aug 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with MySQL / PHP Pagination

    Been working at it for the last few hours and im sad to say im getting nowhere with it... Basic PHP / MySQL is easy but pagination ive never done...

    Heres the code. I hope someone can help:

    Code:
    <?php
    //This page display a topic
    include ("includes/template/header.php");
    if(isset($_GET['id']))
    {
    	$id = intval($_GET['id']);
    	$dn1 = mysql_fetch_array(mysql_query('select count(t.id) as nb1, t.title, t.parent, count(t2.id) as nb2, c.name from topics as t, topics as t2, categories as c where t.id="'.$id.'" and t.id2=1 and t2.id="'.$id.'" and c.id=t.parent group by t.id'));
    if($dn1['nb1']>0)
    {
    ?>
    
    <?php
    if(isset($_SESSION['username']))
    {
    $nb_new_pm = mysql_fetch_array(mysql_query('select count(*) as nb_new_pm from pm where ((user1="'.$_SESSION['userid'].'" and user1read="no") or (user2="'.$_SESSION['userid'].'" and user2read="no")) and id2="1"'));
    $nb_new_pm = $nb_new_pm['nb_new_pm'];
    ?>
    
    <?php
    }
    else
    {
    ?>
    
    <?php
    }
    ?>
    <?php
    if(isset($_SESSION['username']))
    {
    ?>
    
    <?php
    }
    $dn2 = mysql_query('select t.id2, t.authorid, t.message, t.timestamp, u.username as author, u.avatar from topics as t, users as u where t.id="'.$id.'" and u.id=t.authorid order by t.timestamp asc');
    ?>
    
    
    <?php
    while($dnn2 = mysql_fetch_array($dn2))
    {
    ?>
    
    <div class="row">
                            <div class="span2">
                                <div class="ddate">
                                	<h5><i class="icon-calendar"></i> <?php echo date('d/m/Y'); ?></h5>
                                	<div class="firstA"></div>
                                </div>
                                <div class="meta">
                                
                                	<span><?php
    if($dnn2['avatar']!='')
    {
    	echo '<img src="'.htmlentities($dnn2['avatar']).'" style="max-width:100px;max-height:100px;" />';
    }
    ?><a href="profile.php?id=<?php echo $dnn2['authorid']; ?>"><h3 class="colored" align="center"><?php echo $dnn2['author']; ?></h3></a></span>
                                    <center><span><strong><i class="icon-user"></i> Time Posted:</strong> <?php echo date(' H:i:s', $dnn2['timestamp']); ?></span></center>
                            	</div>
                                <?php if(isset($_SESSION['username']) and $_SESSION['username']==$admin){ ?>
                                <hr>
                                
                                <div class="addthis_toolbox addthis_default_style ">
                                    <a class="btn btn-success" href="edit_message.php?id=<?php echo $id; ?>&id2=<?php echo $dnn2['id2']; ?>">Edit</a>
                                </div>
                                <hr>
                                <?php } ?>
                            </div>
                            <div class="span6">
                                <div class="blog_item">
                                	<div class="blog_head">
                                        <h3><?php echo $dn1['title']; ?></h3>
                                    </div>
                                    <p style="word-wrap: break-word;"><?=$dnn2['message'];?></p>
                                </div>
                            </div>
                    	</div>
    
                        <?php
    }
    ?>
    
    
    <?php
    if(isset($_SESSION['username']))
    {
    ?>
    	<a class="btn btn-success pull-right" href="new_reply.php?id=<?php echo $id; ?>" >Reply</a>
    <?php
    }
    else
    {
    ?>
    
    
    <div class="box_login">
    	<form action="login.php" method="post">
    		<label for="username">Username</label><input type="text" name="username" id="username" /><br />
    		<label for="password">Password</label><input type="password" name="password" id="password" /><br />
            <label for="memorize">Remember</label><input type="checkbox" name="memorize" id="memorize" value="yes" />
            <div class="center">
    	        <input type="submit" value="Login" /> <input type="button" onclick="javascript:document.location='signup.php';" value="Sign Up" />
            </div>
        </form>
    </div>
    <?php
    }
    ?><?php
    }
    else
    {
    	echo '<h2>This topic doesn\'t exist.</h2>';
    }
    }
    else
    {
    	echo '<h2>The ID of this topic is not defined.</h2>';
    }
    ?>
    
    <div class="pagination">
      <ul>
        <li><a href="#">Prev</a></li>
        <li class="active">
          <a href="#">1</a>
        </li>
        <li><a href="#">2</a></li>
        <li><a href="#">3</a></li>
        <li><a href="#">4</a></li>
        <li><a href="#">Next</a></li>
      </ul>
    </div>
    <?php include ("includes/template/footer.php"); ?>
    </div>
    Ideally need like 5 entries to be displayed at a time.

    Thanks in advance
    Last edited by MacDudeUK; 08-13-2012 at 12:49 AM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    There are lots of tutorials out there, and that's a good way to start with the basics to get it going the first time. After that, it's pretty easy to adjust what you need.

    Personally I like this tutorial, but there are many more available if you don't
    http://www.php-mysql-tutorial.com/wi...using-php.aspx
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •