SitePoint Sponsor |
|
User Tag List
Results 1 to 25 of 45
Thread: GuestBook
-
Oct 4, 2007, 07:16 #1
- 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
-
Oct 4, 2007, 07:18 #2
- 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
-
Oct 4, 2007, 07:47 #3
- 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.
-
Oct 4, 2007, 07:52 #4
- 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...
-
Oct 4, 2007, 07:57 #5
- Join Date
- Jun 2006
- Posts
- 177
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Oct 4, 2007, 07:57 #6
- 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");
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
-
Oct 4, 2007, 08:03 #7
- 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.
-
Oct 5, 2007, 00:10 #8
- 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 } ?>
-
Oct 5, 2007, 00:22 #9
- Join Date
- Jun 2006
- Posts
- 177
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Use limit in your SQL query.
-
Oct 5, 2007, 00:45 #10
- 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
-
Oct 5, 2007, 01:02 #11
- 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)
-
Oct 5, 2007, 01:40 #12
- 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">
}
?>
-
Oct 5, 2007, 01:43 #13
- 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.
-
Oct 5, 2007, 01:51 #14
- 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
-
Oct 5, 2007, 01:52 #15
- 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
-
Oct 5, 2007, 01:54 #16
- 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">'; } ?>
-
Oct 5, 2007, 02:00 #17
- Join Date
- Sep 2007
- Posts
- 47
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Imstuck with the buttons
-
Oct 5, 2007, 02:04 #18
- 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.
-
Oct 5, 2007, 02:05 #19
- Join Date
- Jun 2006
- Posts
- 177
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Can you show us the code that's giving trouble?
-
Oct 5, 2007, 02:21 #20
- 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 } ?>
-
Oct 5, 2007, 02:27 #21
- 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]";
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
-
Oct 5, 2007, 02:35 #22
- 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
-
Oct 5, 2007, 03:58 #23
- 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>
-
Oct 5, 2007, 04:16 #24
- 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
-
Oct 5, 2007, 05:50 #25
- 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