PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 15, 2022

[FIXED] multiplying a value in a row dynamically before returning it

 March 15, 2022     codeigniter, php     No comments   

Issue

i have this code :

 $query = $this->db->get();
 $query->row()->price * $colors['quantity'];
$response = $query->row();
return $response;

i'm trying to multiply the price dynamically based on the quantity value, but it does not do nothing, as it returns the row as it is,it doesn't seem logical to me that it does not work, as im multiplying that value before the return, even if i put static value like

 $query->row()->price * 2;

still will ignore it


Solution

There is the query builder class to compute the product of price and quantity when selecting it.

You can write:

$this->db->select('price, quantity, price * quantity AS total_amount', FALSE);
$this->db->from('mytable');
$query = $this->db->get();


Answered By - Oluwafemi Sule
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing