0

I use this piece of code to display data from my database on my (joomla 2.5) web.

$query
    ->select($db->quoteName(array('Code', 'Name', 'Price', $username)))
    ->from($db->quoteName('mytable'))
    ->where($db->quoteName($username)." != ".$db->quote('0'));

$username is used to display quantity ordered by the client. So there are 4 columns. I want to add 5th column "Total" where there will be the multiplication - "Price" * "$username".

Tried to do it something like:

$query
    ->select(array('Code', 'Name', 'Price', $username, 'Price' * $username as 'Total'))
    ->from($db->quoteName('mytable'))
    ->where($db->quoteName($username)." != ".$db->quote('0'));

But for a reason it doesn't work (blank page). What am I missing? Thanks for your time.

denoo
  • 5
  • 1

1 Answers1

0

I think you have a syntax error. Should be :

 ->select(array('Code', 'Name', 'Price', $username, "Price * $username as Total"))

Also the following line doesnt make any sense, should be checked in php as $username is a php variable:

->where($db->quoteName($username)." != ".$db->quote('0'));
Frank Conry
  • 2,694
  • 3
  • 29
  • 35
  • Also can't find way to get SUM of newly created column Total... Can I do it in the same query? @Frank Conry Thanks in advance – denoo Jan 11 '14 at 08:49
  • you want to sum all the `Total` values? you'll need to `GROUP BY` and do it in a different query. It might be easier for you to do it in the application code (i.e. use php to do it) – Frank Conry Jan 12 '14 at 19:48
  • Thanks again. I'll do it using php. – denoo Jan 13 '14 at 10:33