$res = mysql_query("select * from users order by intPriority desc");
$riders = mysql_num_rows($res);
I have this code above which gives me the row count
can someone give me the full code to get from the same table I have a field named intMSFriends which always has a value of a number in it, I would like to all up all the numbers in this field to give me a total
mysql> describe test4;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| somenumber | tinyint(4) | YES | | NULL | |
| somename | varchar(30) | | | | |
+------------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> select * from test4;
+------------+----------+
| somenumber | somename |
+------------+----------+
| 3 | gg |
| 5 | yh |
| 23 | gg |
| 127 | yh |
| 127 | msft |
+------------+----------+
5 rows in set (0.00 sec)
mysql> select sum(somenumber) from test4;
+-----------------+
| sum(somenumber) |
+-----------------+
| 285 |
+-----------------+
1 row in set (0.01 sec)
mysql> select sum(somenumber), somename from test4
-> group by somename;
+-----------------+----------+
| sum(somenumber) | somename |
+-----------------+----------+
| 26 | gg |
| 127 | msft |
| 132 | yh |
+-----------------+----------+
3 rows in set (0.00 sec)
some exceptions...weird statements you can say that...i am just showing you these to enable better understanding.
/* there are actually five rows available but four rows are displayed because two rows have the same value 127...I am performing sum on a varchar field so it returns zero for each row...*/
mysql> select sum(somename) from test4
-> group by somenumber;
+---------------+
| sum(somename) |
+---------------+
| 0 |
| 0 |
| 0 |
| 0 |
+---------------+
4 rows in set (0.00 sec)
mysql> select sum(somenumber) from test4
-> group by somenumber;
+-----------------+
| sum(somenumber) |
+-----------------+
| 3 |
| 5 |
| 23 |
| 254 | /*addition of two 127s */
+-----------------+
4 rows in set (0.00 sec)
/* this returns error because 'sum' uses grouping and returns only one value but somename would yield all values in the table so both of them cannot go with each other...you can only use one of them at any time.... */
mysql> select sum(somenumber), somename from test4;
ERROR 1140 (42000): Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GR
OUP columns is illegal if there is no GROUP BY clause
$res = mysql_query("select * from users order by intPriority desc");
$riders = mysql_num_rows($res);
I have this code above which gives me the row count
can someone give me the full code to get from the same table I have a field named intMSFriends which always has a value of a number in it, I would like to all up all the numbers in this field to give me a total
$res = mysql_query("select * from users order by intPriority desc");
$riders = mysql_num_rows($res);
I have this code above which gives me the row count
can someone give me the full code to get from the same table I have a field named intMSFriends which always has a value of a number in it, I would like to all up all the numbers in this field to give me a total