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;
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:
This is the image of my 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:
php codeigniter
add a comment |
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:
This is the image of my 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:
php codeigniter
1
where condition?
– M.Hemant
Mar 28 at 7:38
1
usewhere
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
add a comment |
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:
This is the image of my 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:
php codeigniter
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:
This is the image of my 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:
php codeigniter
php codeigniter
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
usewhere
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
add a comment |
1
where condition?
– M.Hemant
Mar 28 at 7:38
1
usewhere
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
add a comment |
2 Answers
2
active
oldest
votes
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));
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
add a comment |
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;
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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));
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
add a comment |
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));
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
add a comment |
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));
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));
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
add a comment |
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
add a comment |
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;
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
add a comment |
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;
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
add a comment |
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;
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;
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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