PDA

View Full Version : Adding a column in the database?


Koutaru
05-10-2003, 01:58 AM
I want to add the #s in a column in the database

example:

rating
4
5
6

total: 15

what query will work for this?
Thanks!

Koutaru
05-10-2003, 03:30 AM
Without that capability, my queries look totally out of hand


$five = $DB_site->query_first("SELECT COUNT(*) AS rating FROM review WHERE title = \"$title\" AND rating=5");
$four = $DB_site->query_first("SELECT COUNT(*) AS rating FROM review WHERE title = \"$title\" AND rating=4");
$three = $DB_site->query_first("SELECT COUNT(*) AS rating FROM review WHERE title = \"$title\" AND rating=3");
$two = $DB_site->query_first("SELECT COUNT(*) AS rating FROM review WHERE title = \"$title\" AND rating=2");
$one = $DB_site->query_first("SELECT COUNT(*) AS rating FROM review WHERE title = \"$title\" AND rating=1");

$totalnumber = $five[rating]*5+$four[rating]*4+$three[rating]*3+$two[rating]*2+$one[rating]*1;

Koutaru
05-10-2003, 03:47 AM
:) Problem solved (I searched all over google)
For future reference to anyone Oo; I'm such a noob


$average = $DB_site->query_first("SELECT AVG(rating) AS rating FROM review WHERE title = \"$title\"");