php - MySQL: Number of subsequent occurrences
I have a table with four columns: id, from, to, msg.
The rows can look like this:
1 - foo - bar - hello
2 - foo - bar - zup?
3 - bar - foo - hi
4 - bar - foo - going okay
5 - bar - foo - you?
Now I wanna know how many times "bar" has tried to "talk" to "foo" without response. Like I wanna count the number of occurrences since "foo" was on the sending end.
In this example, before the next entry, it should return 3.
Is this possible in pure (My)SQL?
I'm using php on the server side.
Thanks for any tips and advice! =)
Answer
Solution:
Give this a go.
It assumes a table name of convo and the id is autoincrementing.
This is just the mysql but the PHP calls can be added quite cleanly if you wrapped it in a function that passes in the from and to variables.
Answer
Solution:
Answer
Solution:
$sql = "SELECT `fieldone` FROM `table` WHERE `fieldone` = 'foo'";
$results = mysql_query($sql);
$FooSendNumber = mysql_num_rows($results);
or
$FooSendNumber = mysql_num_rows(mysql_query($sql));
Oh wait, you want to see pure MySQL too.
Yeah, it's possible:
$sql = "SELECT MYSQL_CALC_FOUND_ROWS `fieldone` FROM `table` WHERE `fieldone` = 'foo';SELECT FOUND_ROWS();"
Should work.
Oh wait, crap, I see, you wanted the number of times without response.