Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: MySQL question.  (Read 6135 times)

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
MySQL question.
« on: July 19, 2006, 02:57:33 pm »

Ok I have a table called "download" in that there's a field that counts the specific downloads for each template. What whould be the syntax to collect the sum of the downloads ??

Table: download
Fields: ID, title, filename, downloads, thumb

I want to get the sum from the "downloads" field in the table "download"...

Patric.
Logged
"It's only dead fish that goes with the flow... "
Updated

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
MySQL question.
« Reply #1 on: July 19, 2006, 03:03:45 pm »

lol, looksie here, patric ;)
http://php.about.com/od/mysqlcommands/g/sql_count.htm

edit: in your example it would be
SELECT COUNT(downloads) FROM download;

edit2: of course, it would be nice if you also provide a context. what do you have in mind -  phpmyadmin editing or php snippet under development?

edit3: (geez...somebody stop me :D) patric, if you want to sum all the downloads you had so far, use this:
http://www.mysqlfreaks.com/statements/29.php
your example:
SELECT SUM(downloads) FROM download;
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
MySQL question.
« Reply #2 on: July 19, 2006, 03:19:34 pm »

mhmmm... yes... as you can see, i was editing my post while you were posting yours... and you've beat me...i' must be getting old and senile...or lack of coffee
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
MySQL question.
« Reply #3 on: July 19, 2006, 03:28:39 pm »

hehe... it's ok... as long as we spammin' :D
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
MySQL question.
« Reply #4 on: July 19, 2006, 03:35:04 pm »

OK, the SUM... got that, and understand it aswell. I get the sum from field downloads in table download. But how the hell do I get it to show on a website...I tried that query stuff, ie
Code: [Select]
$query = "SELECT SUM(downloads) FROM download";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
echo "  (".$r['downloads'].")
";
}
?>
Hehe, don't laugh now...atleast not to much, ok... I am trying (without having a clue whatsoever as to what I'm doing ;))... This show a cupla brackets, but no number :)
Logged
"It's only dead fish that goes with the flow... "
Updated

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
MySQL question.
« Reply #5 on: July 19, 2006, 03:43:03 pm »

Yeay, I wasn't so bloody wrong then :)...just that last thingy. Thanks bakercad...
Logged
"It's only dead fish that goes with the flow... "
Updated

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
MySQL question.
« Reply #6 on: July 19, 2006, 03:56:33 pm »

Quote
Hehe, don't laugh now...atleast not to much, ok... I am trying (without having a clue whatsoever as to what I'm doing ;))... This show a cupla brackets, but no number :)
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
MySQL question.
« Reply #7 on: July 19, 2006, 04:04:09 pm »

Wooohaaa, yes, that's me :) Here's one for you - But the fav is the one in my avatar space, hehe
Logged
"It's only dead fish that goes with the flow... "
Updated

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
MySQL question.
« Reply #8 on: July 19, 2006, 04:18:14 pm »

note: sql table names are usually in plural, and table columns in singular. that way you can easily avoid possible naming errors ;)
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
MySQL question.
« Reply #9 on: July 19, 2006, 04:19:32 pm »

Mhm, and I've made it the other way around... I'll think of that in the future.

Here's one for Luka:

Logged
"It's only dead fish that goes with the flow... "
Updated