Current location: Hot Scripts Forums » Programming Languages » PHP » adding values from mysql


adding values from mysql

Reply
  #1 (permalink)  
Old 05-17-04, 05:40 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
adding values from mysql

hi,

i plan to make a stat section on a program of mine that would display the amount of items a category had and then total it up. my problem is that I dont know how to do it. i mean i know to get the numer of results but i dont know how to do it "x" amount of times. not sure if ne1 gets what im saying but it will output like this:

cat1-300
cat2-300
cat3-500
ect
total-900

if anyone know how to do this please help me. thx very much in advance.

Last edited by darkcarnival; 05-17-04 at 05:46 PM.
Reply With Quote
  #2 (permalink)  
Old 05-17-04, 05:55 PM
Lost Lost is offline
Wannabe Coder
 
Join Date: Mar 2004
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Hrmmm...you will have to set up an array:
(replace 'SOMETABLE' with your table and change the conditional statement as necessary)


$catinfo = mysql_fetch_array(mysql_query("select * from SOMETABLE where SOMEFIELD="somevalue"));


Then use a foreach loop to add them up:
(replace 'amount' with the field of the table in which the number value is location)


$total = 0;
for($catinfo as $cat)
{
$total += $cat[amount];
}
echo "Total: $total";
Reply With Quote
  #3 (permalink)  
Old 05-18-04, 02:14 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
well heres the thing i wont know the know the name of the cateogries. it will be like adding a category and then drawing info from that that cateogry in the DB. not sure if anyone understands this but if you think u can help me better via IM feel free to add me to your list. i have all of them but i currently just use msn & AOL
Reply With Quote
  #4 (permalink)  
Old 05-18-04, 07:24 PM
Lost Lost is offline
Wannabe Coder
 
Join Date: Mar 2004
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
So you have a MySQL table with a name and fields with names. You want to add entries to the table with any values and be able to extract those values without knowing any of them but the table and field names?

I am offering help on this if you can give me a little better explanation. Please drop me an email at kevin@premonitionstudios.com
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
adding values in a database Nightingale Visual Basic 4 05-12-04 08:07 AM
two questions....deleting mysql values and adding array value through forms mlbpa2 PHP 16 03-18-04 09:41 PM
compare number values in mysql? 7crystal7 PHP 1 03-13-04 04:41 AM
Problem with adding content to mysql from php HasansWeb PHP 3 01-10-04 05:26 PM


All times are GMT -5. The time now is 10:35 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.