Jump to content

Recommended Posts

hello first of all sorry for my english and my writing i'm a little in hurry cuz i have to get some sleep i have a simple small question.

 

This is my first time working with php maths and i need to do a script that will do something like this:

 

1. insert a number like 25000 in a table and when i hit a button to show all the data from db i want to make a total.

ex: 25+25 = 50 -> it's about money and i want to see a total after i hit show report... can someone help me with an explanation ..?

Link to comment
https://forums.phpfreaks.com/topic/142391-solved-mysql-php-maths/
Share on other sites

thank you for your reply this is what i want to do:

 

 

CREATE TABLE IF NOT EXISTS `internet_hours` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `price` varchar(70) NOT NULL,
  `how_many_hours` varchar(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

 

i work at internet cafe and i want to know how much money i got how many hours have the clients bought because now we have some sodas and stuff for sale.. and i wanna know exacly how when where.. :)) it's a personal project :)

 

for the moment all i want to do is to insert the price of an hour or half an hour in the db and then get the total of the sum i have there :)

 

 

--
-- Table structure for table `internet_hours`
--

CREATE TABLE IF NOT EXISTS `internet_hours` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `price` varchar(70) NOT NULL,
  `how_many_hours` varchar(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `internet_hours`
--

INSERT INTO `internet_hours` (`id`, `price`, `how_many_hours`) VALUES
(1, '25000', '1'),
(2, '25000', '1');

 

as you see i've inserted some example datas:) and then on my page i will hit show report and then show me a page with all the data for example or only the total sum of the money

aham :)

 

i'm a beginer in php .. and php math it's very new to me .. :) including most of mysql commands i learn .. when a i do something new just for testing or personal.

 

 

after you'v seen the table is it corect your first post ?

 

to use this command :

 

SELECT SUM(column) FROM table WHERE...

It will be

SELECT SUM(price) FROM internet_hours

 

but you HAVE TO change price column to DECIMAL type (or if in your country, prices with decimal places are _extremely_ unlikely, you could use INTEGER - I would advice using DECIMAL with two places after point though)

 

 

[edit]

 

Oh... wait a second. Just realised, you probably want price * how_many_hours :P

 

SELECT SUM(price * how_many_hours) FROM internet_hours

 

And of course you should change a type of 'how_many_hours' to a numeric type as well.

--
-- Table structure for table `internet_hours`
--

CREATE TABLE IF NOT EXISTS `internet_hours` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `price` decimal(10,0) NOT NULL,
  `how_many_hours` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `internet_hours`
--

INSERT INTO `internet_hours` (`id`, `price`, `how_many_hours`) VALUES
(1, '25000', 1),
(2, '25000', 1);

 

i've made the changes :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.