PHP - Times 'Shouted' (Explained more)

Status
Not open for further replies.

zMagenta

Posting Freak
Jul 15, 2011
1,414
682
Hello!

As the title may be mis-leading this is what I mean, right. Is there a way to display the amount of times a user has shouted? So the column for the table which holds their username is 'shouted_by', so I'd want to it to be something like this.

"Spoken: <b><times 'shouted_by'></b> times!"

Do you understand? :cool: If not, happy to go into more detail. Thanks. :p
 

zMagenta

Posting Freak
Jul 15, 2011
1,414
682
What do you mean with 'shouted'?

Whenever someone types a comment, it adds into the table 'shout' with the structure:
'id'
'shouted_by'
'text'
'timestamp'
'ip'.

I want to be able to show the amount of times a user has comment if their ID is above 8. (Is that more help?)
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
PHP:
if ($_SESSION['user']['id'] > 8)
{
$query = mysql_query("SELECT id FROM shout WHERE id = '".$_SESSION['user']['id']."' ");
echo "Spoken: <b>".mysql_num_rows($query)."</b> times!";
}
 

Sean

‫‫‫‫‫‫  ‫  Don't Worry, Be Happy
Dec 12, 2011
1,121
405
What do you mean if there ID is above 8, the way Wess has written his code, the first 8 users that register will not have a post count, but anyone that registers after that will...
 

Sean

‫‫‫‫‫‫  ‫  Don't Worry, Be Happy
Dec 12, 2011
1,121
405
That is exactly what I wanted, ignore the reasons behind it.

Well if that's what you want you may want to use MySQLi :
PHP:
if ($_SESSION['user']['id'] > 8) {
    $id = $_SESSION['user']['id'];
    $result = $mysqli->query("SELECT `id` FROM `shout` WHERE `id` = '{$id}'");
    $count = $result->num_rows;
    echo "Spoken: <b>" . $count . "</b> times!";
    $result->close();
}
 
Status
Not open for further replies.

Users who are viewing this thread

Top