Including already existing variable in a function - php

Im trying to make a function, that takes an input, determines its value, and outputs a word from an already existing array that has been included in the script. The problem is the output is blank, i believe the function ignores variables already in the script, is there a way to change this so existing variables arent ignored by the function?
Here is the function:
The words need to be from an array because of multi-lingual requirements.
function get_genre($id)
{
if($id == "1"){
$genre = $lang['277'];
}
if($id == "2"){
$genre = $lang['278'];
}
if($id == "3"){
$genre = $lang['279'];
}
if($id == "4"){
$genre = $lang['280'];
}
if($id == "5"){
$genre = $lang['281'];
}
if($id == "6"){
$genre = $lang['282'];
}
if($id == "7"){
$genre = $lang['283'];
}
if($id == "8"){
$genre = $lang['284'];
}
if($id == "9"){
$genre = $lang['285'];
}
if($id == "10"){
$genre = $lang['286'];
}
if($id == "11"){
$genre = $lang['287'];
}
if($id == "12"){
$genre = $lang['288'];
}
if($id == "13"){
$genre = $lang['289'];
}
if($id == "14"){
$genre = $lang['290'];
}
if($id == "15"){
$genre = $lang['374'];
}
return $genre;
}

function get_genre($id)
{
global $lang;
....
}
or
function get_genre($id, $lang) //Must pass $lang array to function here
{
}

function get_genre($id)
{
global $lang;
if($id == "1"){
$genre = $lang['277'];
}
if($id == "2"){
$genre = $lang['278'];
}
if($id == "3"){
$genre = $lang['279'];
}
if($id == "4"){
$genre = $lang['280'];
}
if($id == "5"){
$genre = $lang['281'];
}
if($id == "6"){
$genre = $lang['282'];
}
if($id == "7"){
$genre = $lang['283'];
}
if($id == "8"){
$genre = $lang['284'];
}
if($id == "9"){
$genre = $lang['285'];
}
if($id == "10"){
$genre = $lang['286'];
}
if($id == "11"){
$genre = $lang['287'];
}
if($id == "12"){
$genre = $lang['288'];
}
if($id == "13"){
$genre = $lang['289'];
}
if($id == "14"){
$genre = $lang['290'];
}
if($id == "15"){
$genre = $lang['374'];
}
return $genre;
}

While this isn't ideal, have you considered using an associative array?
var $lookupArray = array();
$lookupArray["1"] = $lang['274'];
....
Then you can call it like this:
function get_genre($id)
{
return(array_key_exists($id,$lookupArray)) ? $lookupArray[$id] : null;
}

Related

Which is equivalent for PHP Include at CodeIgniter3?

Please explain to me how to do it:
<?php
if(!isset($_GET['s'])) {
$_GET['s'] = ""; }
if ($_GET['s'] == "") { include("Templates/Tutorial/1.tpl"); }
if ($_GET['s'] == "1") { include("Templates/Tutorial/1.tpl"); }
if ($_GET['s'] == "2") { include("Templates/Tutorial/2.tpl"); }
if ($_GET['s'] == "3") { include("Templates/Tutorial/3.tpl"); }
if ($_GET['s'] == "4") { include("Templates/Tutorial/4.tpl"); }
if ($_GET['s'] == "5") { include("Templates/Tutorial/5.tpl"); }
?>
Thank you very much!
I think this will also work
<?php
$inc = 1;
if(isset($_GET['s']) && $_GET['s'] != ""):
$inc = (int)$_GET['s'];
endif;
include("Templates/Tutorial/$inc.tpl");
?>

Codeigniter update records error

I am using codeigniter framework, and I keep getting this error when I submit my from to post to my database.
Controller
public function profilePic()
{
if ($this->session->userdata('userLogin')) {
$user_id = $this->session->userdata('user_id');
$data = array();
if (isset($_POST['add'])) {
$pic = $this->input->post('profileFace');
$front = $this->input->post('frontView');
$left = $this->input->post('leftView');
$right = $this->input->post('rightView');
$back = $this->input->post('backView');
$updtResult = $this->main_model->updateProfilePic($pic,$front,$left,$right,$back,$user_id);
redirect("userProfile");
} else {
$data['userdata'] = $this->main_model->getUserData();
$this->load->view("frontend/ajax-view", $data);
}
} else {
redirect("/fitness");
}
}
Model
function updateProfilePic($pic,$front,$left,$right,$back,$user_id) {
$check = $this->getUserData();
if(count($check)!=0)
{
if($pic != "")
{
$data['image'] = $pic;
}
if($front != "")
{
$data['front_view'] = $front;
}
if($left != "")
{
$data['left_view'] = $left;
}
if($right != "")
{
$data['right_view'] =$right;
}
if($back != "")
{
$data['back_view'] = $back;
}
// pr($data);
$this->db->where('user_id',$user_id);
$result = $this->db->update('fitness_users', $data);
}
return $result;
}
and the error i am getting is:
You can use set method to update your data and check your variable is set or not using isset()
if (isset($pic) && $pic != "") {
$this->db->set("image", $pic);
}
if (isset($front) && $front != "") {
$this->db->set("front_view", $front);
}
if (isset($left) && $left != "") {
$this->db->set("left_view", $left);
}
if (isset($right) && $right != "") {
$this->db->set("right_view", $right);
}
if (isset($back) && $back != "") {
$this->db->set("back_view", $back);
}
// pr($data);
$this->db->where('user_id', $user_id);
$result = $this->db->update('fitness_users');

Need help to add second condition to existing code

I am trying to add a second condition to existing code but it doesn't seem to be working.
The conditions are:
Compare two strings, from different arrays (working)
And check the value of a third string from a different array (not
working)
Here is the working code without the second condition: http://pastebin.com/bfpNb9zw
Here is my attempt:
Basically, the bit I am trying to get working is this part && ($ca = '') && ($ca = '0') && ($ca = '1') but it seems $ca is not able to be read outside the loop
if(!function_exists('lookup')){
function lookup($chain, $type) {
$cacount = count($chain['tbsCertificate']['extensions']);
for($j = 0; $j < $cacount; $j++) {
$count = count($chain['tbsCertificate'][$type]['rdnSequence']);
$exists = array('utf8String', 'printableString', 'teletexString', 'bmpString', 'universalString', 'ia5String');
$oid = array('id-at-commonName');
for($i = 0; $i < $count; $i++) {
foreach($exists as $field) {
if(
array_key_exists($field, $chain['tbsCertificate'][$type]['rdnSequence'][$i][0]['value']) &&
in_array($chain['tbsCertificate'][$type]['rdnSequence'][$i][0]['type'], $oid)
) {
$value = $chain['tbsCertificate'][$type]['rdnSequence'][$i][0]['value'][$field];
return $value;
$ca = '';
if(isset($chain['tbsCertificate']['extensions'][$j]['extnValue']['cA'])) {
$ca = $chain['tbsCertificate']['extensions'][$j]['extnValue']['cA'];
}
}
}
}
}
return null;
}
}
if (lookup($chain, 'subject') != lookup($chain, 'issuer') && ($ca == '')) {
echo 'end entity';
}
elseif (lookup($chain, 'subject') != lookup($chain, 'issuer') && ($ca == '0')) {
echo 'secondary ca';
}
elseif (lookup($chain, 'subject') != lookup($chain, 'issuer') && ($ca == '1')) {
echo 'primary ca';
} else {
echo 'Root';
}
You are using =, which sets the value of $ca. You should be using === to check the value, instead.
Example:
if (lookup($chain, 'subject') != lookup($chain, 'issuer') && ($ca === '')) {
echo 'end entity';
}
elseif (lookup($chain, 'subject') != lookup($chain, 'issuer') && ($ca === '0')) {
echo 'secondary ca';
}
elseif (lookup($chain, 'subject') != lookup($chain, 'issuer') && ($ca === '1')) {
echo 'primary ca';
} else {
echo 'Root';
}

Show progress image of a user profile

I'm trying to show the progress of a user filling out their user profile by an image sequence.
Example, if the user fills out their name, progress image 2 will show up.
If the user fills out their name and bio, progress image 3 will appear, and so on....
I'm trying to use if and elseif statements, but only progress image 2 will appear.
So basically, I just want one image to show based on the progress the users has made on completing the user profile form.
Here is my code.
<?php
$name = ($data->first_name);
$bio = ($data->bio);
$address = ($data->street1);
$phone = ($data->phone);
$ec = ($data->e_contact);
$ecp = ($data->e_phone);
$bs = ($data->bs);
if($name == true){?>
<img src="../images/progress2.png" class="img-max-progress">
<?php }
elseif($name.$bio == true){?>
<img src="../images/progress3.png" class="img-max-progress">
<?php
}
elseif($name.$bio.$address == true){?>
<img src="../images/progress4.png" class="img-max-progress">
<?php
}
elseif($name.$bio.$address.$phone == true){?>
<img src="../images/progress5.png" class="img-max-progress">
<?php
}
elseif($name.$bio.$address.$phone.$ec == true){?>
<img src="../images/progress6.png" class="img-max-progress">
<?php
}
elseif($name.$bio.$address.$phone.$ec.$ecp == true){?>
<img src="../images/progress7.png" class="img-max-progress">
<?php
}
elseif($name.$bio.$address.$phone.$ec.$ecp.$bs == true){?>
<img src="../images/progress8.png" class="img-max-progress">
<?php
}
?>
<?php
if($name != true){?>
<img src="../images/progress1.png" class="img-max-progress">
<?php
}
?>
I have the form filled out so progress8.png should be the image that is shown,
but progress2.png is currently showing.
Using a combo between #user3132781 and #vlzvl answers, I got it working like this.
<?php
$name = ($data->first_name);
$bio = ($data->bio);
$address = ($data->street1);
$phone = ($data->phone);
$ec = ($data->e_contact);
$ecp = ($data->e_phone);
$bs = ($data->bs);
$completed = 0;
if (empty($name)) {
$completed += 1;
}
if (!empty($name)) {
$completed += 2;
}
if (!empty($bio)) {
$completed += 1;
}
if (!empty($address)) {
$completed += 1;
}
if (!empty($phone)) {
$completed += 1;
}
if (!empty($ec)) {
$completed += 1;
}
if (!empty($ecp)) {
$completed += 1;
}
if (!empty($bs)) {
$completed += 1;
}
echo '<img src="../images/progress' . $completed .'.png" class="img-max-progress">';
?>
I have an other approach - just as a suggestion:
$completed = 0;
if (isset($name)) {
$completed += 1;
}
if (isset($adress)) {
$completed += 1;
}
..... and so on for all the fields
//$completed can be used for defining the image
echo '<img src="../images/progress' . $completed .'.png" class="img-max-progress">';
Hmmm.. I would try something along the lines of:
if($name){
img 1
}
elseif ($name && $bio){
img 2
}
etc.
The final line would be:
if(!$name){
img progress1
}
Try this (it is also a lot cleaner):
<?php
$name = ($data->first_name);
$bio = ($data->bio);
$address = ($data->street1);
$phone = ($data->phone);
$ec = ($data->e_contact);
$ecp = ($data->e_phone);
$bs = ($data->bs);
if($name == true) {
echo '<img src="../images/progress2.png" class="img-max-progress">';
}
elseif($name== true && $bio == true) {
echo '<img src="../images/progress3.png" class="img-max-progress">';
}
elseif($name== true && $bio == true && $address == true) {
echo '<img src="../images/progress4.png" class="img-max-progress">';
}
elseif($name== true && $bio == true && $address == true && $phone == true) {
echo '<img src="../images/progress5.png" class="img-max-progress">';
}
elseif($name== true && $bio == true && $address == true && $phone == true && $ec == true) {
echo '<img src="../images/progress6.png" class="img-max-progress">';
}
elseif($name== true && $bio == true && $address == true && $phone == true && $ec == true && $ecp == true) {
echo '<img src="../images/progress7.png" class="img-max-progress">';
}
elseif($name== true && $bio == true && $address == true && $phone == true && $ec == true && $ecp == true && $bs == true) {
echo '<img src="../images/progress8.png" class="img-max-progress">';
}
if($name != true) {
echo '<img src="../images/progress1.png" class="img-max-progress">';
}
You maybe want to change the == true to what #vlzvl says (check if a variable is empty or not)

Form's data can not post (Codeigniter)

i am working on Codigniter,i have a issue with posting form's data..
in my form,there is different section,i have put array for that different section
Here is my code (Controller)
<?php
class Resume extends CI_Controller{
var $user_id;
function __construct(){
parent::__construct();
$this->user_id = $this->session->userdata('user_id');
$this->load->model("Resume_model");
if($this->session->userdata('user_id') == NULL){
redirect('user/login','refresh');
}
}
public function index(){
$this->Resume();
}
public function Resume(){
if($this->input->post('Skills')){
$Resume = $this->input->post();
$ResumeInsert=array();
$ResumeUpdate=array();
$Key_Resume__ExistIDs=array();
foreach($this->input->post('Person_id') as $key =>$value ){
$ResumeInsert[$key]['updated'] = Date("Y-m-d");
$ResumeInsert[$key]['Importance_JK'] = $Resume['Importance_JK'];
$ResumeInsert[$key]['user_FK'] = $user_id;
$ResumeInsert[$key]['Person_id'] = $Resume['Person_id'][$key];
$ResumeInsert[$key]['email_contact'] = $Resume['email_contact'][$key];
$ResumeInsert[$key]['Contact_Phone'] = $Resume['Contact_Phone'][$key];
$ResumeInsert[$key]['communication'] = $Resume['communication'][$key];
$ResumeInsert[$key]['creativity'] = $Resume['creativity'][$key];
$ResumeInsert[$key]['team_work'] = $Resume['team_work'][$key];
$ResumeInsert[$key]['organizational'] = $Resume['organizational'][$key];
$ResumeInsert[$key]['Leadership'] = $Resume['Leadership'][$key];
$ResumeInsert[$key]['Productivity'] = $Resume['Productivity'][$key];
$ResumeInsert[$key]['Postal_Address'] = $Resume['Postal_Address'][$key];
$ResumeInsert[$key]['Career_objective'] = $Resume['Career_objective'][$key];
}
foreach($this->input->post('emp_id') as $key =>$value ){
$ResumeInsert[$key]['resume_keyid'] = $Resume['emp_id'][$key];
$ResumeInsert[$key]['employer_name'] = $Resume['employer_name'][$key];
$ResumeInsert[$key]['start_Date'] = $Resume['start_Date'][$key];
$ResumeInsert[$key]['end_date'] = $Resume['end_date'][$key];
$ResumeInsert[$key]['type_id'] = $Resume['type_id'][$key];
$ResumeInsert[$key]['position'] = $Resume['position'][$key];
$ResumeInsert[$key]['responsibility'] = $Resume['responsibility'][$key];
$ResumeInsert[$key]['Skills'] = $Resume['Skills'][$key];
print_r ($ResumeInsert);exit;
}
foreach($this->input->post('resume_id1') as $key =>$value ){
$ResumeInsert[$key]['edu_id'] = $Resume['resume_id1'][$key];
$ResumeInsert[$key]['year_gain'] = $Resume['year_gain'][$key];
$ResumeInsert[$key]['qualification_name'] = $Resume['qualification_name'][$key];
$ResumeInsert[$key]['institution_name'] = $Resume['institution_name'][$key];
$ResumeInsert[$key]['outstanding_Ach'] = $Resume['outstanding_Ach'][$key];
$ResumeInsert[$key]['aquired_skill'] = $Resume['aquired_skill'][$key];
$ResumeInsert[$key]['expiry'] = $Resume['expiry'][$key];
$ResumeInsert[$key]['Application_of_Skill'] = $Resume['Application_of_Skill'][$key];
}
foreach($this->input->post('resume_id2') as $key =>$value ){
$ResumeInsert[$key]['resume_skillID'] = $Resume['resume_id2'][$key];
$ResumeInsert[$key]['skill_name'] = $Resume['skill_name'][$key];
$ResumeInsert[$key]['Licences_permits'] = $Resume['Licences_permits'][$key];
$ResumeInsert[$key]['date_Achived'] = $Resume['date_Achived'][$key];
$ResumeInsert[$key]['expiry_renewal'] = $Resume['expiry'][$key];
$ResumeInsert[$key]['skill_work'] = $Resume['application_of_skill'][$key];
$ResumeInsert[$key]['course_tilte'] = $Resume['course_tilte'][$key];
}
foreach($this->input->post('resume_id3') as $key =>$value ){
$ResumeInsert[$key]['hobbyId'] = $Resume['resume_id3'][$key];
$ResumeInsert[$key]['hobby_name'] = $Resume['hobby_name'][$key];
$ResumeInsert[$key]['achievement_name'] = $Resume['achievement_name'][$key];
$ResumeInsert[$key]['Application_OF_hobby_work'] = $Resume['Application_of_Skill'][$key];
}
foreach($this->input->post('resume_id4') as $key =>$value ){
$ResumeInsert[$key]['ref_resume_ID'] = $Resume['resume_id4'][$key];
$ResumeInsert[$key]['referee_name'] = $Resume['referee_name'][$key];
$ResumeInsert[$key]['Position_referee'] = $Resume['Position'][$key];
$ResumeInsert[$key]['company_name_ref'] = $Resume['company_name'][$key];
$ResumeInsert[$key]['phone_ref'] = $Resume['phone_ref'][$key];
$ResumeInsert[$key]['contact_email_ref'] = $Resume['contact_email'][$key];
$ResumeInsert[$key]['reference_Type'] = $Resume['reference_Type'][$key];
$ResumeInsert[$key]['Application_of_Skill_ref'] = $Resume['Application_of_Skill'][$key];
}
foreach($this->input->post('resume_id5') as $key =>$value ){
$ResumeInsert[$key]['Application_Id'] = $Resume['resume_id5'][$key];
$ResumeInsert[$key]['app_date_sent'] = $Resume['date_sent'][$key];
$ResumeInsert[$key]['app_busisness_name'] = $Resume['app_busisness_name'][$key];
$ResumeInsert[$key]['app_address'] = $Resume['app_address'][$key];
$ResumeInsert[$key]['app_contact_phone'] = $Resume['app_contact_phone'][$key];
$ResumeInsert[$key]['app_outcome'] = $Resume['app_outcome'][$key];
$ResumeInsert[$key]['app_date_closed'] = $Resume['app_date_closed'][$key];
}
if(isset($Resume['id'][$key]))
{
// echo "test";exit;
$Key_Resume__ExistIDs[]=$Resume['id'][$key];
if( $ResumeInsert[$key]['Person_id'] != ""){
$ResumeUpdate[$key]['Person_id'] = $ResumeInsert[$key]['Person_id'];
}
if( $ResumeInsert[$key]['email_contact'] != ""){
$ResumeUpdate[$key]['email_contact'] = $ResumeInsert[$key]['email_contact'];
}
if( $ResumeInsert[$key]['Contact_Phone'] != ""){
$ResumeUpdate[$key]['Contact_Phone'] = $ResumeInsert[$key]['Contact_Phone'];
}
if( $ResumeInsert[$key]['communication'] != ""){
$ResumeUpdate[$key]['communication'] = $ResumeInsert[$key]['communication'];
}
if( $ResumeInsert[$key]['creativity'] != ""){
$ResumeUpdate[$key]['creativity'] = $ResumeInsert[$key]['creativity'];
}
if( $ResumeInsert[$key]['team_work'] != ""){
$ResumeUpdate[$key]['team_work'] = $ResumeInsert[$key]['team_work'];
}
if( $ResumeInsert[$key]['organizational'] != ""){
$ResumeUpdate[$key]['organizational'] = $ResumeInsert[$key]['organizational'];
}
if( $ResumeInsert[$key]['Leadership'] != ""){
$ResumeUpdate[$key]['Leadership'] = $ResumeInsert[$key]['Leadership'];
}
if( $ResumeInsert[$key]['Productivity'] != ""){
$ResumeUpdate[$key]['Productivity'] = $ResumeInsert[$key]['Productivity'];
}
if( $ResumeInsert[$key]['Postal_Address'] != ""){
$ResumeUpdate[$key]['Postal_Address'] = $ResumeInsert[$key]['Postal_Address'];
}
if( $ResumeInsert[$key]['Career_objective'] != ""){
$ResumeUpdate[$key]['Career_objective'] = $ResumeInsert[$key]['Career_objective'];
}
if( $ResumeInsert[$key]['resume_keyid'] != ""){
$ResumeUpdate[$key]['resume_keyid'] = $ResumeInsert[$key]['resume_keyid'];
}
if( $ResumeInsert[$key]['employer_name'] != ""){
$ResumeUpdate[$key]['employer_name'] = $ResumeInsert[$key]['employer_name'];
}
if( $ResumeInsert[$key]['start_Date'] != ""){
$ResumeUpdate[$key]['start_Date'] = $ResumeInsert[$key]['start_Date'];
}
if( $ResumeInsert[$key]['end_date'] != "") {
$ResumeUpdate[$key]['end_date'] = $ResumeInsert[$key]['end_date'];
}
if( $ResumeInsert[$key]['type_id'] != ""){
$ResumeUpdate[$key]['type_id'] = $ResumeInsert[$key]['type_id'];
}
if( $ResumeInsert[$key]['position'] != ""){
$ResumeUpdate[$key]['position'] = $ResumeInsert[$key]['position'];
}
if( $ResumeInsert[$key]['edu_id'] != ""){
$ResumeUpdate[$key]['edu_id'] = $ResumeInsert[$key]['edu_id'];
}
if( $ResumeInsert[$key]['year_gain'] != ""){
$ResumeUpdate[$key]['year_gain'] = $ResumeInsert[$key]['year_gain'];
}
if( $ResumeInsert[$key]['qualification_name'] != ""){
$ResumeUpdate[$key]['qualification_name'] = $ResumeInsert[$key]['qualification_name'];
}
if( $ResumeInsert[$key]['institution_name'] != ""){
$ResumeUpdate[$key]['institution_name'] = $ResumeInsert[$key]['institution_name'];
}
if( $ResumeInsert[$key]['outstanding_Ach'] != ""){
$ResumeUpdate[$key]['outstanding_Ach']= $ResumeInsert[$key]['outstanding_Ach'];
}
if( $ResumeInsert[$key]['aquired_skill'] != ""){
$ResumeUpdate[$key]['aquired_skill'] = $ResumeInsert[$key]['aquired_skill'];
}
if( $ResumeInsert[$key]['expiry'] != ""){
$ResumeUpdate[$key]['expiry'] = $ResumeInsert[$key]['expiry'];
}
if( $ResumeInsert[$key]['Application_of_Skill'] != ""){
$ResumeUpdate[$key]['Application_of_Skill'] = $ResumeInsert[$key]['Application_of_Skill'];
}
if( $ResumeInsert[$key]['resume_skillID'] != ""){
$ResumeUpdate[$key]['resume_skillID'] = $ResumeInsert[$key]['resume_skillID'];
}
if( $ResumeInsert[$key]['skill_name'] != ""){
$ResumeUpdate[$key]['skill_name'] = $ResumeInsert[$key]['skill_name'];
}
if( $ResumeInsert[$key]['Licences_permits'] != ""){
$ResumeUpdate[$key]['Licences_permits'] = $ResumeInsert[$key]['Licences_permits'];
}
if( $ResumeInsert[$key]['date_Achived'] != ""){
$ResumeUpdate[$key]['date_Achived'] = $ResumeInsert[$key]['date_Achived'];
}
if( $ResumeInsert[$key]['expiry_renewal'] !="") {
$ResumeUpdate[$key]['expiry_renewal'] = $ResumeInsert[$key]['expiry_renewal'];
}
if( $ResumeInsert[$key]['skill_work'] != ""){
$ResumeUpdate[$key]['skill_work'] = $ResumeInsert[$key]['skill_work'];
}
if( $ResumeInsert[$key]['course_tilte'] != ""){
$ResumeUpdate[$key]['course_tilte'] = $ResumeInsert[$key]['course_tilte'];
}
if( $ResumeInsert[$key]['hobbyId'] != ""){
$ResumeUpdate[$key]['hobbyId'] = $ResumeInsert[$key]['hobbyId'];
}
if( $ResumeInsert[$key]['hobby_name'] != ""){
$ResumeUpdate[$key]['hobby_name'] = $ResumeInsert[$key]['hobby_name'];
}
if( $ResumeInsert[$key]['achievement_name'] != ""){
$ResumeUpdate[$key]['achievement_name'] = $ResumeInsert[$key]['achievement_name'];
}
if( $ResumeInsert[$key]['Application_OF_hobby_work'] != ""){
$ResumeUpdate[$key]['Application_OF_hobby_work'] = $ResumeInsert[$key]['Application_OF_hobby_work'];
}
if( $ResumeInsert[$key]['ref_resume_ID'] != ""){
$ResumeUpdate[$key]['ref_resume_ID'] = $ResumeInsert[$key]['ref_resume_ID'];
}
if( $ResumeInsert[$key]['referee_name'] != ""){
$ResumeUpdate[$key]['referee_name'] = $ResumeInsert[$key]['referee_name'];
}
if( $ResumeInsert[$key]['Position_referee'] != ""){
$ResumeUpdate[$key]['Position_referee'] = $ResumeInsert[$key]['Position_referee'];
}
if( $ResumeInsert[$key]['company_name_ref'] != ""){
$ResumeUpdate[$key]['company_name_ref'] = $ResumeInsert[$key]['company_name_ref'];
}
if( $ResumeInsert[$key]['phone_ref'] != ""){
$ResumeUpdate[$key]['phone_ref'] = $ResumeInsert[$key]['phone_ref'];
}
if( $ResumeInsert[$key]['contact_email_ref'] != ""){
$ResumeUpdate[$key]['contact_email_ref'] = $ResumeInsert[$key]['contact_email_ref'];
}
if( $ResumeInsert[$key]['reference_Type'] != ""){
$ResumeUpdate[$key]['reference_Type'] = $ResumeInsert[$key]['reference_Type'];
}
if( $ResumeInsert[$key]['Application_of_Skill_ref'] != ""){
$ResumeUpdate[$key]['Application_of_Skill_ref'] = $ResumeInsert[$key]['Application_of_Skill_ref'];
}
if( $ResumeInsert[$key]['app_date_sent'] != ""){
$ResumeUpdate[$key]['app_date_sent'] = $ResumeInsert[$key]['app_date_sent'];
}
if( $ResumeInsert[$key]['Application_Id'] != ""){
$ResumeUpdate[$key]['Application_Id'] = $ResumeInsert[$key]['Application_Id'];
}
if( $ResumeInsert[$key]['app_busisness_name'] != ""){
$ResumeUpdate[$key]['app_busisness_name'] = $ResumeInsert[$key]['app_busisness_name'];
}
if( $ResumeInsert[$key]['app_address'] != ""){
$ResumeUpdate[$key]['app_address'] = $ResumeInsert[$key]['app_address'];
}
if( $ResumeInsert[$key]['app_contact_phone'] != "")
{
$ResumeUpdate[$key]['app_contact_phone'] = $ResumeInsert[$key]['app_contact_phone'];
}
if( $ResumeInsert[$key]['app_outcome'] != ""){
$ResumeUpdate[$key]['app_outcome'] = $ResumeInsert[$key]['app_outcome'];
}
if( $ResumeInsert[$key]['app_date_closed'] != ""){
$ResumeUpdate[$key]['app_date_closed'] = $ResumeInsert[$key]['app_date_closed'];
}
if( $ResumeInsert[$key]['resume_id'] != ""){
$ResumeUpdate[$key]['resume_id'] = $ResumeInsert[$key]['resume_id'];
}
$ResumeUpdate[$key]['resume_id']=$Resume['id'][$key];
unset($ResumeInsert[$key]);
}
else{
$ResumeInsert[$key]['resume_id'] = $GetLastID;
$GetLastID++;
}
$status=$this->Resume_model->ProcessData($idsToDelete,$ResumeUpdate,$user_id,$ResumeInsert,$imgInsert,$imgUpdate);
redirect('Resume','refresh');
}
}
?>
Here the insert query (model)
function ProcessData($tbl_resumeInsert){
if(!empty($tbl_resumeInsert))
{
$this->insert_tbl_resume($user_id,$tbl_resumeInsert);
}
}
function insert_tbl_resume($id,$arrtbl_resume)
{
$this->db->insert_batch('tbl_resume', $arrtbl_resume);
}
in above code,when im going to submit the form only first Foreach loop's data can insert,when i print $ResumeInsert,it shows me only first foreach loop's data foreach($this->input->post('Person_id') as $key =>$value )
Rest foreach loop's data appears NULL in DB
please any help?
Thank You!
The function $this->input->post('something') is returning a value from the $_POST array with a key of 'something'. If the key 'something' does not exist it returns NULL. (or FALSE in CI version < 3.0)
$_POST is an associative array and will have at most only one item with any given key. So the code
foreach($this->input->post('Person_id') as $key =>$value )
{
...
will only run once as there is only one $_POST array item with the key 'Person_id'.
If your form html has more than one field named 'Person_id' only the value from the last field will be posted to the server.

Categories