Numbers in guestbook

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Bonta_SWE
Forum Newbie
Posts: 14
Joined: Thu Sep 18, 2003 7:04 pm
Location: Sweden, Skåne

Numbers in guestbook

Post by Bonta_SWE »

Hi!
Im a newbe in php and want some help.
I want to print a number for each guestbook contribution
The guestbook use a mySQL.

example:
3 persons have write something in my guestbook
and i want to print

Number: 1
Number: 2
Number: 3

Not the entire guestbook, just the number of each contribution

Thanx
----------------------
excuse my english spelling
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Could you share a database table structure or two?

If you have a incrementing id field associated with guestbook entries then you could just echo that.

... otherwise it gets more complex.
Bonta_SWE
Forum Newbie
Posts: 14
Joined: Thu Sep 18, 2003 7:04 pm
Location: Sweden, Skåne

Post by Bonta_SWE »

Hi
My database table for the guestbook are
------------
id auto_increment
name
email
url
message
------------

hope this is helping you
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Code: Select all

//connect to database and select DB
$sql = "SELECT * FROM table";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
echo "Number: " . $row['id'];
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

LiLpunkSkateR wrote:

Code: Select all

//connect to database and select DB
$sql = "SELECT * FROM table";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo "Number: " . $row['id'];
}
fixed a little missing element for debugging...
Bonta_SWE
Forum Newbie
Posts: 14
Joined: Thu Sep 18, 2003 7:04 pm
Location: Sweden, Skåne

Post by Bonta_SWE »

Thx but this just echo the id number.
I want to echo the number for each post in my guestbook

example.

3 persons have sign my guestbook.
We then have 3 id in guestbook.
If i delete number 2, then the next person that sign my guestbook will get id 4, and this print number 4. But its just 3 posts in my guestbook
Get it ? =)

Dont know how to explain it, my english are not so good..
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Code: Select all

<?php
$sql = "SELECT COUNT(*) FROM table"; 
$result = mysql_query($sql) or die(mysql_error()); 
$row = mysql_fetch_array($result))
echo "Number of signers: " . $row['0']; 
?>
Bonta_SWE
Forum Newbie
Posts: 14
Joined: Thu Sep 18, 2003 7:04 pm
Location: Sweden, Skåne

Post by Bonta_SWE »

magicrobotmonkey

Got Parse error: parse error

$row = mysql_fetch_array($result))
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

replace the second ) with ;
Bonta_SWE
Forum Newbie
Posts: 14
Joined: Thu Sep 18, 2003 7:04 pm
Location: Sweden, Skåne

Post by Bonta_SWE »

hmm

<?php
$sql = "SELECT COUNT(*) FROM table";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
echo "Number: " . $row['0'];
?>

this show the result of all the signers right ??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

should show how many signers there are, yes.
Bonta_SWE
Forum Newbie
Posts: 14
Joined: Thu Sep 18, 2003 7:04 pm
Location: Sweden, Skåne

Post by Bonta_SWE »

Ok.
ehh let me se how to explain what i mean.

Visit the link below, and you will se what i mean.

http://www.olzzon.com/g/g.php?a=s&i=g10-01617-96

Look at "Nummer" on each post
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

LilPunkSkater's original post would do this... :roll:
Bonta_SWE
Forum Newbie
Posts: 14
Joined: Thu Sep 18, 2003 7:04 pm
Location: Sweden, Skåne

Post by Bonta_SWE »

Thanx for the help
i give up,,, i dont get it to work. All i get is the total of id in the guestbook,
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you didn't seem to read my post...

Code: Select all

//connect to database and select DB
$sql = "SELECT * FROM table";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo "Number: " . $row['id'];
}
should do (almost) exactly what you said.. this isn't rocket science..
Post Reply