adding contents of sql in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tabatsoy
Forum Commoner
Posts: 29
Joined: Thu Mar 13, 2008 10:14 am

adding contents of sql in php

Post by tabatsoy »

greetings earthlings!

How to add the contents of my sql into php?
for example i have table scores: math = 3, english = 2, logic = 3, total = Null
how can i add the 3 columns in php?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: adding contents of sql in php

Post by onion2k »

Well, if you insist on doing it in PHP just get the record from the database and add the columns like you'd access anything else... eg

Code: Select all

$total = $record->maths + $record->english + $record->logic;
You'd be better off doing the maths in the SQL though.
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Re: adding contents of sql in php

Post by Rovas »

Use a simple script to get the data from the MySQL tables into an array (there are lots of tutorials on the net) and then add them.
Do your math in PHP not in MySQL it' s much faster and you don' t load your database.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: adding contents of sql in php

Post by onion2k »

Rovas wrote:Do your math in PHP not in MySQL it' s much faster and you don' t load your database.
That's completely wrong.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: adding contents of sql in php

Post by John Cartwright »

It is advisable to put as much in the querying itself as possible, as Onion already mentioned.
Post Reply