Page 1 of 2
Numbers in guestbook
Posted: Wed Jun 16, 2004 6:17 am
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
Posted: Wed Jun 16, 2004 7:27 am
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.
Posted: Wed Jun 16, 2004 10:28 am
by Bonta_SWE
Hi
My database table for the guestbook are
------------
id auto_increment
name
email
url
message
------------
hope this is helping you
Posted: Wed Jun 16, 2004 11:33 am
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'];
}
Posted: Wed Jun 16, 2004 12:22 pm
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...
Posted: Wed Jun 16, 2004 1:41 pm
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..
Posted: Wed Jun 16, 2004 1:43 pm
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'];
?>
Posted: Wed Jun 16, 2004 1:49 pm
by Bonta_SWE
magicrobotmonkey
Got Parse error: parse error
$row = mysql_fetch_array($result))
Posted: Wed Jun 16, 2004 1:50 pm
by feyd
replace the second ) with ;
Posted: Wed Jun 16, 2004 2:05 pm
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 ??
Posted: Wed Jun 16, 2004 2:30 pm
by feyd
should show how many signers there are, yes.
Posted: Wed Jun 16, 2004 2:35 pm
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
Posted: Wed Jun 16, 2004 2:46 pm
by feyd
LilPunkSkater's original post would do this...

Posted: Wed Jun 16, 2004 2:56 pm
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,
Posted: Wed Jun 16, 2004 3:07 pm
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..