Page 1 of 1
adding contents of sql in php
Posted: Tue Mar 25, 2008 4:10 am
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?
Re: adding contents of sql in php
Posted: Tue Mar 25, 2008 4:16 am
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.
Re: adding contents of sql in php
Posted: Tue Mar 25, 2008 9:00 am
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.
Re: adding contents of sql in php
Posted: Tue Mar 25, 2008 10:27 am
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.
Re: adding contents of sql in php
Posted: Tue Mar 25, 2008 10:34 am
by John Cartwright
It is advisable to put as much in the querying itself as possible, as Onion already mentioned.