SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 45

Thread: GuestBook

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    GuestBook

    Hi im now making a simple guestbook. The problem is about displaying the number of comments . The maximum of commecnts to be display is 4. And i have a button. First, Previous, Next, Last. I have an idea but dont know how to start with it

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What do you have so far?

    I think it's just a case of some simple pagination.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually im not started to code yet. Im just planning and thinking of the problem that i may take. And the difficult one is the navigation of displaying the comments. The maximum number of comments to be displayed must be 4. About navigation i have 4 buttons like i said its First,Prev,Nxt,Lst.

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup, that's pagination. It's quite fun to figure out by yourself, although if you're new, it can be a bit frustrating as well. There's a similar question on that a bit earlier. Lemme fetch the link...

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What I would do is have a mysql table for the comments. Use this query to fetch the results. increasing $_GET['commentpage'] will change the page. If $_GET['commentpage'] is not set, then it defaults to 0.
    PHP Code:
    $page = (isset($_GET['commentpage'])) ? $_GET['commentpage'] : 0;
    $start $page 4;
    $q mysql_query("SELECT * FROM `comments` LIMIT $start,4"); 
    Make the next button add 1 to $_GET['commentpage'] on the url, for example:
    PHP Code:
    <?
    $nextpage 
    $page 1;
    echo 
    "<a href=\"?commentpage=".$nextpage."\">Next</a>";
    ?>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok let me try your code and also i try my own code even its too long using a for loop.

  8. #8
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the code i use to display the comments, who post it, and the date posted it.

    PHP Code:
    <?php

    $getdata
    ="SELECT * FROM comments ORDER BY com_id DESC";

    $getdata2=mysql_query($getdata) or die("Could not get data");

    while(
    $getdata3=mysql_fetch_array($getdata2))

    {

      
    $getdata3[com_name]=strip_tags($getdata3[com_name]);
      
    $getdata3[com_message]=strip_tags($getdata3[com_message]);
      
    $getdata3[com_date]=strip_tags($getdata3[com_date]);
      

    ?>
      

      
            <div class="headinglarge"> Title <img src="images/del.gif"></div><div class="adminbtn"><img src="images/admin.gif" width="65" height="52" border="0" ></div>
            <div class="headingsub"> <?php "$getdata3[com_date]"?> by <?php echo "$getdata3[com_name]"?></div>
            <div class="content"> <?php echo "$getdata3[com_message]"?>
                    </div><hr>
    <?php ?>
    But how im gonna limit that into 4 contents only and the other post must be in the other page when i click the button next or previous or last or first.

  9. #9
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use limit in your SQL query.

  10. #10
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I place the Limit 4. on my sql variable. but what if i press the next button or previous button should i place a limit 4 also. but how im gonna attain that if i meet the last record the next button is not enable

  11. #11
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You got to make a variable for the first and last number. It won't be LIMIT 0,4, but LIMIT $start, $stop. You change $start and $stop according to the button pressed (Next/Previous/Last/First)

  12. #12
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok but before that how im gonna display an image inside the php code

    PHP Code:
    <?php
    for ($i=0$i>"$getdata3[com_rating]"$i++)
    {
    echo <
    img src="star.gif">
    }
    ?>
    This is not working

  13. #13
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't show star.gif any time, I bet. Read your for loop aloud:

    i is 0. While i is bigger than getdata3[com_rating], draw star.gif, then increase i by one.

    That would require get_data3 to be negative in value, and if that would be the case, it would loop endlessly.

  14. #14
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh ! i wrote a wrong for loop. It should be "<=" not ">". The reason the image doesn't show because i put a double quote of it

  15. #15
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    so, your fixed code there would be:
    PHP Code:
    <?
    for($i 0$i $getdata3$i++){
         
    ?><img src="star.gif" alt="star" /><?
    }
    ?>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  16. #16
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uhmmm, I see. Dunno how I didn't see this before.
    Code:
    <?php
    for ($i=0; $i<$getdata3["com_rating"]; $i++)
    {
    echo '<img src="star.gif">';
    }
    ?>
    Try it like that. The quotes should be around the associative array key, not the entire variable.

  17. #17
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Imstuck with the buttons

  18. #18
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in the images i fixed it already but in the buttons im stuck.

  19. #19
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you show us the code that's giving trouble?

  20. #20
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    <?php 
    for ($x=1$x>"getdata3[com_id]"$x++)
    {
    ?>
            <table width="119" border="0" align="center" cellpadding="0" cellspacing="3">
              <tr>
                <td width="16" align="right"><?php $x?><img src="images/pfirst.gif" width="15" height="16"></td>
                <td width="16" align="right"><?php $x?><img src="images/pprev.gif" width="15" height="16"></td>
                <td width="7" align="center"><?php $x?>1</td>
                <td width="16" align="left"><?php $x?><img src="images/pnext.gif" width="15" height="16"></td>
                <td width="46" align="left"><?php $x?><img src="images/plast.gif" width="15" height="16"></td>
              </tr>
            </table>
            <?php ?>
    I know this is wrong but im still getting the idea of how to to that

  21. #21
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    don't put quotes around variables.
    change
    PHP Code:
    $x>"getdata3[com_id]"
    to
    PHP Code:
    $x>$getdata3["com_id"]; 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  22. #22
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But is it my code do the displaying 4 by 4 . if i click it will go to the 4 comments again and if previous the vice versa. and so on

  23. #23
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im really stuck with it. Dont know what to do with my buttons

    PHP Code:
    <?php

    $getdata
    ="SELECT * FROM comments ORDER BY com_id DESC LIMIT 0,4";

    $getdata2=mysql_query($getdata) or die("Could not get data");

    while(
    $getdata3=mysql_fetch_array($getdata2))

    {

      
    $getdata3[com_name]=strip_tags($getdata3[com_name]);
      
    $getdata3[com_rating]=strip_tags($getdata3[com_rating]);
      
    $getdata3[com_message]=strip_tags($getdata3[com_message]);
      
    $getdata3[com_date]=strip_tags($getdata3[com_date]);
      

    ?>
      

      
    <div class="headinglarge"> Title <?php
    for ($i=1$i<="$getdata3[com_rating]"$i++)
    {
    echo 
    '<img src="images/star.gif">';
    }
     
    ?><img src="images/del.gif"></div><div class="adminbtn"><img src="images/admin.gif" width="65" height="52" border="0" ></div>
    <div class="headingsub"> <?php echo "$getdata3[com_date]"?> by <?php echo "$getdata3[com_name]"?></div>
    <div class="content"> <?php echo "$getdata3[com_message]"?>
    </div><hr>
    <?php ?>
            <table width="119" border="0" align="center" cellpadding="0" cellspacing="3">
              <tr>
                <td width="16" align="right"><img src="images/pfirst.gif" width="15" height="16"></td>
                <td width="16" align="right"><img src="images/pprev.gif" width="15" height="16"></td>
                <td width="7" align="center">1</td>
                <td width="16" align="left"><img src="images/pnext.gif" width="15" height="16"></td>
                <td width="46" align="left"><img src="images/plast.gif" width="15" height="16"></td>
              </tr>
            </table>

  24. #24
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    read post 6
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  25. #25
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what is this all about ?
    PHP Code:
    (isset($_Get['commentpage'])) 


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
  •