I want to compute specific field in my db depends on ID_numberQuerying MySQL with CodeIgniter, selecting rows where field is NULLHow do I check if a string contains a specific word?Returning and using multidimensional array of records from database in CodeIgniter 2.0codeigniter join table techniqueHow to extract field values from query resultIn database table there is no rows means getting error Undefined variable: results using codeigniteri want to make selection from database for a given date intervalFetching value from a query result in the controllerCan't display values for a user profile in CodeIgniter?Codeigniter: count total number of rows in a view which retrieved from database

How there are 3 possible tautomers of 2,2,4-trimethylheptane-3,5-dione?

What happens when a file that is 100% paged in to the page cache gets modified by another process

Is there a "right" way to interpret a novel, if not, how do we make sure our novel is interpreted correctly?

If every star in the universe except the Sun were destroyed, would we die?

When did computers stop checking memory on boot?

Why is the the worst case for this function O(n*n)

Text is continuing wider than the width of the page and not passing to new line

Why would an AC motor heavily shake when driven with certain frequencies?

Is a MySQL database a viable alternative to LDAP?

Why does low tire pressure decrease fuel economy?

How to find a reviewer/editor for my paper?

Stack class in Java8

How do we create our own symbolisms?

The pirate treasure of Leatherback Atoll

Can multiple public keys lead to the same shared secret in x25519?

Is every sentence we write or utter either true or false?

Why do the British opposition parties not want a new election?

Bit floating sequence

When calculating averages, why can we treat exploding die as if they're independent?

Can you mark a new target with the Hunter's Mark spell if the original target shifts to a different plane?

How do Scrum teams manage their dependencies on other teams?

How can Schrödinger's cat be both dead and alive?

How do you say "to hell with everything" in French?

Are there any space probes or landers which regained communication after being lost?



I want to compute specific field in my db depends on ID_number


Querying MySQL with CodeIgniter, selecting rows where field is NULLHow do I check if a string contains a specific word?Returning and using multidimensional array of records from database in CodeIgniter 2.0codeigniter join table techniqueHow to extract field values from query resultIn database table there is no rows means getting error Undefined variable: results using codeigniteri want to make selection from database for a given date intervalFetching value from a query result in the controllerCan't display values for a user profile in CodeIgniter?Codeigniter: count total number of rows in a view which retrieved from database






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-3















This is my model



public function total_late()


$query = "SELECT sum(late_deduction) as late_deduction FROM tbl_dtr";
$result = $this->db->query($query);
return $result->row()->late_deduction;



This the image of the database:



db



This is the image of my table:



table



This is my another model for my table in view



function get_faculty_payroll($limit, $start, $string = "", $orderField, $orderDirection)

$this->db->group_start()
->where('tbl_employee' . '.department_id', 3)
->group_end()
->group_start()
->or_like('first_name', $string)
->or_like('last_name', $string)
->group_end()
->join('tbl_employee_department', 'tbl_employee.department_id = tbl_employee_department.department_id')
->join('tbl_rates', 'tbl_employee.ID_number = tbl_rates.ID_number')
->limit($limit, $start)
->order_by($orderField, $orderDirection);
$query = $this->db->get('tbl_employee');
return $query->result();




This is my table:



enter image description here










share|improve this question





















  • 1





    where condition?

    – M.Hemant
    Mar 28 at 7:38






  • 1





    use where condition

    – Devsi Odedra
    Mar 28 at 7:40











  • Are you trying to output a new field name and calculate the value depending on the number of the id?

    – user2203703
    Mar 28 at 7:54

















-3















This is my model



public function total_late()


$query = "SELECT sum(late_deduction) as late_deduction FROM tbl_dtr";
$result = $this->db->query($query);
return $result->row()->late_deduction;



This the image of the database:



db



This is the image of my table:



table



This is my another model for my table in view



function get_faculty_payroll($limit, $start, $string = "", $orderField, $orderDirection)

$this->db->group_start()
->where('tbl_employee' . '.department_id', 3)
->group_end()
->group_start()
->or_like('first_name', $string)
->or_like('last_name', $string)
->group_end()
->join('tbl_employee_department', 'tbl_employee.department_id = tbl_employee_department.department_id')
->join('tbl_rates', 'tbl_employee.ID_number = tbl_rates.ID_number')
->limit($limit, $start)
->order_by($orderField, $orderDirection);
$query = $this->db->get('tbl_employee');
return $query->result();




This is my table:



enter image description here










share|improve this question





















  • 1





    where condition?

    – M.Hemant
    Mar 28 at 7:38






  • 1





    use where condition

    – Devsi Odedra
    Mar 28 at 7:40











  • Are you trying to output a new field name and calculate the value depending on the number of the id?

    – user2203703
    Mar 28 at 7:54













-3












-3








-3








This is my model



public function total_late()


$query = "SELECT sum(late_deduction) as late_deduction FROM tbl_dtr";
$result = $this->db->query($query);
return $result->row()->late_deduction;



This the image of the database:



db



This is the image of my table:



table



This is my another model for my table in view



function get_faculty_payroll($limit, $start, $string = "", $orderField, $orderDirection)

$this->db->group_start()
->where('tbl_employee' . '.department_id', 3)
->group_end()
->group_start()
->or_like('first_name', $string)
->or_like('last_name', $string)
->group_end()
->join('tbl_employee_department', 'tbl_employee.department_id = tbl_employee_department.department_id')
->join('tbl_rates', 'tbl_employee.ID_number = tbl_rates.ID_number')
->limit($limit, $start)
->order_by($orderField, $orderDirection);
$query = $this->db->get('tbl_employee');
return $query->result();




This is my table:



enter image description here










share|improve this question
















This is my model



public function total_late()


$query = "SELECT sum(late_deduction) as late_deduction FROM tbl_dtr";
$result = $this->db->query($query);
return $result->row()->late_deduction;



This the image of the database:



db



This is the image of my table:



table



This is my another model for my table in view



function get_faculty_payroll($limit, $start, $string = "", $orderField, $orderDirection)

$this->db->group_start()
->where('tbl_employee' . '.department_id', 3)
->group_end()
->group_start()
->or_like('first_name', $string)
->or_like('last_name', $string)
->group_end()
->join('tbl_employee_department', 'tbl_employee.department_id = tbl_employee_department.department_id')
->join('tbl_rates', 'tbl_employee.ID_number = tbl_rates.ID_number')
->limit($limit, $start)
->order_by($orderField, $orderDirection);
$query = $this->db->get('tbl_employee');
return $query->result();




This is my table:



enter image description here







php codeigniter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 8:53









halfer

15.3k7 gold badges63 silver badges128 bronze badges




15.3k7 gold badges63 silver badges128 bronze badges










asked Mar 28 at 7:36









GeloGelo

13 bronze badges




13 bronze badges










  • 1





    where condition?

    – M.Hemant
    Mar 28 at 7:38






  • 1





    use where condition

    – Devsi Odedra
    Mar 28 at 7:40











  • Are you trying to output a new field name and calculate the value depending on the number of the id?

    – user2203703
    Mar 28 at 7:54












  • 1





    where condition?

    – M.Hemant
    Mar 28 at 7:38






  • 1





    use where condition

    – Devsi Odedra
    Mar 28 at 7:40











  • Are you trying to output a new field name and calculate the value depending on the number of the id?

    – user2203703
    Mar 28 at 7:54







1




1





where condition?

– M.Hemant
Mar 28 at 7:38





where condition?

– M.Hemant
Mar 28 at 7:38




1




1





use where condition

– Devsi Odedra
Mar 28 at 7:40





use where condition

– Devsi Odedra
Mar 28 at 7:40













Are you trying to output a new field name and calculate the value depending on the number of the id?

– user2203703
Mar 28 at 7:54





Are you trying to output a new field name and calculate the value depending on the number of the id?

– user2203703
Mar 28 at 7:54












2 Answers
2






active

oldest

votes


















0
















Your Controller



public function total_late()

$retRes=$this->modelname->total_late($ID_number);



Your model



public function total_late($ID_number)


$query = "SELECT sum(late_deduction) as late_deduction
FROM tbl_dtr WHERE ID_number = '$ID_number'";
$result = $this->db->query($query);
return $result->row()->late_deduction;



However, this code is better, as it handles parameters safely, and avoids SQL injection vulnerabilities:



$stmt = $this->db->prepare("
SELECT sum(late_deduction) as late_deduction
FROM tbl_dtr WHERE ID_number = ?
");

$stmt->execute(array($ID_number));





share|improve this answer



























  • it's not showing anything

    – Gelo
    Mar 28 at 8:02











  • at first it says undefined variable ID_number ,, then i tried declaring ID_number in my controller ,, then it displays nothing..

    – Gelo
    Mar 28 at 8:03












  • actually sir it did work when i chose the specific ID_number but im trying to show it in one table with different ID_numbers

    – Gelo
    Mar 28 at 8:18






  • 1





    @halfer: Sir please check I edited my answer.

    – SAVe
    Apr 1 at 7:23


















0
















Try This,



public function total_late()

$query = "SELECT sum(late_deduction) as late_deduction FROM tbl_dtr where ID_number = 'C-08011'";
$result = $this->db->query($query);
return $result->row()->late_deduction;






share|improve this answer

























  • it did compute the row with the of C-08011 but how about the other one??

    – Gelo
    Mar 28 at 7:51











  • im trying to show it on a table

    – Gelo
    Mar 28 at 7:52














Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392307%2fi-want-to-compute-specific-field-in-my-db-depends-on-id-number%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0
















Your Controller



public function total_late()

$retRes=$this->modelname->total_late($ID_number);



Your model



public function total_late($ID_number)


$query = "SELECT sum(late_deduction) as late_deduction
FROM tbl_dtr WHERE ID_number = '$ID_number'";
$result = $this->db->query($query);
return $result->row()->late_deduction;



However, this code is better, as it handles parameters safely, and avoids SQL injection vulnerabilities:



$stmt = $this->db->prepare("
SELECT sum(late_deduction) as late_deduction
FROM tbl_dtr WHERE ID_number = ?
");

$stmt->execute(array($ID_number));





share|improve this answer



























  • it's not showing anything

    – Gelo
    Mar 28 at 8:02











  • at first it says undefined variable ID_number ,, then i tried declaring ID_number in my controller ,, then it displays nothing..

    – Gelo
    Mar 28 at 8:03












  • actually sir it did work when i chose the specific ID_number but im trying to show it in one table with different ID_numbers

    – Gelo
    Mar 28 at 8:18






  • 1





    @halfer: Sir please check I edited my answer.

    – SAVe
    Apr 1 at 7:23















0
















Your Controller



public function total_late()

$retRes=$this->modelname->total_late($ID_number);



Your model



public function total_late($ID_number)


$query = "SELECT sum(late_deduction) as late_deduction
FROM tbl_dtr WHERE ID_number = '$ID_number'";
$result = $this->db->query($query);
return $result->row()->late_deduction;



However, this code is better, as it handles parameters safely, and avoids SQL injection vulnerabilities:



$stmt = $this->db->prepare("
SELECT sum(late_deduction) as late_deduction
FROM tbl_dtr WHERE ID_number = ?
");

$stmt->execute(array($ID_number));





share|improve this answer



























  • it's not showing anything

    – Gelo
    Mar 28 at 8:02











  • at first it says undefined variable ID_number ,, then i tried declaring ID_number in my controller ,, then it displays nothing..

    – Gelo
    Mar 28 at 8:03












  • actually sir it did work when i chose the specific ID_number but im trying to show it in one table with different ID_numbers

    – Gelo
    Mar 28 at 8:18






  • 1





    @halfer: Sir please check I edited my answer.

    – SAVe
    Apr 1 at 7:23













0














0










0









Your Controller



public function total_late()

$retRes=$this->modelname->total_late($ID_number);



Your model



public function total_late($ID_number)


$query = "SELECT sum(late_deduction) as late_deduction
FROM tbl_dtr WHERE ID_number = '$ID_number'";
$result = $this->db->query($query);
return $result->row()->late_deduction;



However, this code is better, as it handles parameters safely, and avoids SQL injection vulnerabilities:



$stmt = $this->db->prepare("
SELECT sum(late_deduction) as late_deduction
FROM tbl_dtr WHERE ID_number = ?
");

$stmt->execute(array($ID_number));





share|improve this answer















Your Controller



public function total_late()

$retRes=$this->modelname->total_late($ID_number);



Your model



public function total_late($ID_number)


$query = "SELECT sum(late_deduction) as late_deduction
FROM tbl_dtr WHERE ID_number = '$ID_number'";
$result = $this->db->query($query);
return $result->row()->late_deduction;



However, this code is better, as it handles parameters safely, and avoids SQL injection vulnerabilities:



$stmt = $this->db->prepare("
SELECT sum(late_deduction) as late_deduction
FROM tbl_dtr WHERE ID_number = ?
");

$stmt->execute(array($ID_number));






share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 1 at 7:27









halfer

15.3k7 gold badges63 silver badges128 bronze badges




15.3k7 gold badges63 silver badges128 bronze badges










answered Mar 28 at 7:54









SAVeSAVe

7802 silver badges19 bronze badges




7802 silver badges19 bronze badges















  • it's not showing anything

    – Gelo
    Mar 28 at 8:02











  • at first it says undefined variable ID_number ,, then i tried declaring ID_number in my controller ,, then it displays nothing..

    – Gelo
    Mar 28 at 8:03












  • actually sir it did work when i chose the specific ID_number but im trying to show it in one table with different ID_numbers

    – Gelo
    Mar 28 at 8:18






  • 1





    @halfer: Sir please check I edited my answer.

    – SAVe
    Apr 1 at 7:23

















  • it's not showing anything

    – Gelo
    Mar 28 at 8:02











  • at first it says undefined variable ID_number ,, then i tried declaring ID_number in my controller ,, then it displays nothing..

    – Gelo
    Mar 28 at 8:03












  • actually sir it did work when i chose the specific ID_number but im trying to show it in one table with different ID_numbers

    – Gelo
    Mar 28 at 8:18






  • 1





    @halfer: Sir please check I edited my answer.

    – SAVe
    Apr 1 at 7:23
















it's not showing anything

– Gelo
Mar 28 at 8:02





it's not showing anything

– Gelo
Mar 28 at 8:02













at first it says undefined variable ID_number ,, then i tried declaring ID_number in my controller ,, then it displays nothing..

– Gelo
Mar 28 at 8:03






at first it says undefined variable ID_number ,, then i tried declaring ID_number in my controller ,, then it displays nothing..

– Gelo
Mar 28 at 8:03














actually sir it did work when i chose the specific ID_number but im trying to show it in one table with different ID_numbers

– Gelo
Mar 28 at 8:18





actually sir it did work when i chose the specific ID_number but im trying to show it in one table with different ID_numbers

– Gelo
Mar 28 at 8:18




1




1





@halfer: Sir please check I edited my answer.

– SAVe
Apr 1 at 7:23





@halfer: Sir please check I edited my answer.

– SAVe
Apr 1 at 7:23













0
















Try This,



public function total_late()

$query = "SELECT sum(late_deduction) as late_deduction FROM tbl_dtr where ID_number = 'C-08011'";
$result = $this->db->query($query);
return $result->row()->late_deduction;






share|improve this answer

























  • it did compute the row with the of C-08011 but how about the other one??

    – Gelo
    Mar 28 at 7:51











  • im trying to show it on a table

    – Gelo
    Mar 28 at 7:52
















0
















Try This,



public function total_late()

$query = "SELECT sum(late_deduction) as late_deduction FROM tbl_dtr where ID_number = 'C-08011'";
$result = $this->db->query($query);
return $result->row()->late_deduction;






share|improve this answer

























  • it did compute the row with the of C-08011 but how about the other one??

    – Gelo
    Mar 28 at 7:51











  • im trying to show it on a table

    – Gelo
    Mar 28 at 7:52














0














0










0









Try This,



public function total_late()

$query = "SELECT sum(late_deduction) as late_deduction FROM tbl_dtr where ID_number = 'C-08011'";
$result = $this->db->query($query);
return $result->row()->late_deduction;






share|improve this answer













Try This,



public function total_late()

$query = "SELECT sum(late_deduction) as late_deduction FROM tbl_dtr where ID_number = 'C-08011'";
$result = $this->db->query($query);
return $result->row()->late_deduction;







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 28 at 7:42









M.HemantM.Hemant

2,1701 gold badge5 silver badges13 bronze badges




2,1701 gold badge5 silver badges13 bronze badges















  • it did compute the row with the of C-08011 but how about the other one??

    – Gelo
    Mar 28 at 7:51











  • im trying to show it on a table

    – Gelo
    Mar 28 at 7:52


















  • it did compute the row with the of C-08011 but how about the other one??

    – Gelo
    Mar 28 at 7:51











  • im trying to show it on a table

    – Gelo
    Mar 28 at 7:52

















it did compute the row with the of C-08011 but how about the other one??

– Gelo
Mar 28 at 7:51





it did compute the row with the of C-08011 but how about the other one??

– Gelo
Mar 28 at 7:51













im trying to show it on a table

– Gelo
Mar 28 at 7:52






im trying to show it on a table

– Gelo
Mar 28 at 7:52



















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392307%2fi-want-to-compute-specific-field-in-my-db-depends-on-id-number%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript