herghost Posted November 17, 2010 Share Posted November 17, 2010 Hi all, for some reason I cant see this blantantly obvious query. I have 3 rows in my database, all with an id of 1, their is a column called price which contains three different float values, how the hell do I write a query in php for this?! $q = mysql_query("SELECT price FROM mytable WHERE id=1") ???? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/219011-having-a-brain-block-adding-numbers-from-database/ Share on other sites More sharing options...
Pikachu2000 Posted November 17, 2010 Share Posted November 17, 2010 You forgot to mention what this query should do exactly. Should it return the total, echo them each individually, or what? Quote Link to comment https://forums.phpfreaks.com/topic/219011-having-a-brain-block-adding-numbers-from-database/#findComment-1135790 Share on other sites More sharing options...
herghost Posted November 17, 2010 Author Share Posted November 17, 2010 Sorry, having a forgetful evening! I want all the totals added together and then displayed, basically a total price Quote Link to comment https://forums.phpfreaks.com/topic/219011-having-a-brain-block-adding-numbers-from-database/#findComment-1135794 Share on other sites More sharing options...
Pikachu2000 Posted November 17, 2010 Share Posted November 17, 2010 Try "SELECT SUM(price) FROM mytable WHERE id=1" Quote Link to comment https://forums.phpfreaks.com/topic/219011-having-a-brain-block-adding-numbers-from-database/#findComment-1135799 Share on other sites More sharing options...
ManiacDan Posted November 17, 2010 Share Posted November 17, 2010 First of all, you're not writing a query in PHP, you're writing it in SQL. New programmers don't usually understand that they're using up to 5 languages at once. PHP, SQL, JavaScript, HTML, and Regular Expressions are all stand-alone languages. Secondly, bah, pikachu beat me. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/219011-having-a-brain-block-adding-numbers-from-database/#findComment-1135800 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.