I have a set of tables for job listing. Right now I have a job table with id that is linked to multiple other tables that contain requirements for this job.
For example:
Job Responsiblities
Job Duties
Job Desired Skills
Job Required Skills
…..and so on. Lets say 10 different tables.
The way my code is set up now I’m getting a couple levels of arrays returned. I’m wondering if there is a way to get rid of one of the levels. OR if this is how it should look. The returned data is displayed on a PHP Page. Some of the information returned is going to a table (Job Title, city, state, country). The rest - tables listed above will be put to a simple list in sections for each job. So an example of that will be:
Job 1
Job Title
Job Responsiblities list
Job Duties list
Job Desired Skills list
Job Required Skills list
Job 2
Job Title
Job Responsiblities list
Job Duties list
Job Desired Skills list
Job Required Skills list
Here is what my return looks like using the <pre> </pre> tags
Array ( [0] => Array ( [job_id] => 94 [jobOpening_ID] => 287 [customer] => customer [datePosted] => 2013-12-19 [dateRemoved] => 0000-00-00 [jobtitle] => jobTitle [city] => loc_city [state] => loc_State [country] => loc_Country [experience] => Experience [open] => 1 [summary] => Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary Summary [0] => Array ( [0] => Array ( [resp] => Array ( [0] => Job ID 94 Responsibility 1 [1] => Job ID 94 Responsibility 2 [2] => Job ID 94 Responsibility 3 [3] => Job ID 94 Responsibility 4 [4] => Job ID 94 Responsibility 5 ) ) ) [1] => Array ( [0] => Array ( [duties] => Array ( [0] => Job ID 94 Duty 1 [1] => Job ID 94 Duty 2 [2] => Job ID 94 Duty 3 [3] => Job ID 94 Duty 4 [4] => Job ID 94 Duty 5 ) ) ) ) [1] => Array ( [job_id] => 92 [jobOpening_ID] => 305 [customer] => Cust - ABC [datePosted] => 2013-12-12 [dateRemoved] => 0000-00-00 [jobtitle] => ABC Job Title [city] => Location City [state] => Location State [country] => Location Country [experience] => ABC Experience [open] => 1 [summary] => Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello [0] => Array ( [0] => Array ( [resp] => Array ( [0] => Job ID 92 Resp 1 [1] => Job ID 92 Resp 2 [2] => Job ID 92 Resp 3 [3] => Job ID 92 Resp 4 [4] => Upgrade hardware/software knowledge and skills through tutorials, seminars, and education ) ) ) [1] => Array ( [0] => Array ( [duties] => Array ( [0] => Job ID 92 Duty 1 [1] => Job ID 92 Duty 2 [2] => Job ID 92 Duty 3 [3] => Job ID 92 Duty 4 [4] => Job ID 92 Duty 5 ) ) ) ) )
I'm wondering if I can / should remove the third [0]..
[0][0][0][resp]
[0][0][0][duties]
Code:
function jb_return(){ try{ global $db; //Prepare query - Limit 2 now for testing $jb_return_set = $db->prepare("SELECT * from job order by job_id desc LIMIT 2"); //execute $jb_return_set->execute(); //Get results from returned object $jb_return_array = $jb_return_set->fetchAll(PDO::FETCH_ASSOC); //Transfer the returned array - Not sure if I need this, but I wanted to keep the original $jb_return_array as is $jb_full_array_return = $jb_return_array; /* * Get Job Specific Details */ $count = 0; foreach($jb_return_array as $cur_id){ //echo '<script type="text/javascript">alert("Job ID Returned is: '. $cur_id['job_id'] .'")</script>'; //Get Job Responsibilities and add the array to the job array $jb_resp= array(); $jb_resp = get_jb_resp($cur_id['job_id']); array_push($jb_full_array_return[$count], array($jb_resp)); //Get Job Duties and add the array to the job array $jb_duty= array(); $jb_duty = get_jb_duties($cur_id['job_id']); array_push($jb_full_array_return[$count], array($jb_duty)); //Get Job Skills and add the array to the job array //Get Job Desired Skills and add the array to the job array // and so on with the other tables ++$count; } //Return result return $jb_full_array_return; } catch(PDOException $e){ echo 'ERROR: Inside jb_return Function' . $e->getMessage(); } } function get_jb_resp($jb_id){ //echo '<script type="text/javascript">alert("Inside the get_jb_resp - Job ID is: '.$jb_id.'")</script>'; try{ global $db; //Prepare query $jb_resp_set = $db->prepare("SELECT resp from job_resp where job_id = :jb_id and resp !=\"\""); //Bind the Value $jb_resp_set->bindValue(':jb_id', $jb_id, PDO::PARAM_STR); //execute $jb_resp_set->execute(); //Get results from returned object $jb_resp_array = $jb_resp_set->fetchAll(PDO::FETCH_ASSOC); foreach ($jb_resp_array as $row){ $return_jb_resp_array['resp'][] = $row['resp']; } //return $jb_resp_array; return $return_jb_resp_array; } catch(PDOException $e){ echo 'ERROR: Inside get_jb_resp Function' . $e->getMessage(); } } function get_jb_duties($jb_id){ try{ global $db; //Prepare query $get_jb_duty_set = $db->prepare("SELECT duties from job_resp where job_id = :jb_id and duties !=\"\""); //Bind the Value $get_jb_duty_set->bindValue(':jb_id', $jb_id, PDO::PARAM_STR); //execute $get_jb_duty_set->execute(); //Get results from returned object $get_jb_duty_array = $get_jb_duty_set->fetchAll(PDO::FETCH_ASSOC); foreach ($get_jb_duty_array as $row){ $return_jb_duty_array['duties'][] = $row['duties']; } //return $jb_resp_array; return $return_jb_duty_array; } catch(PDOException $e){ echo 'ERROR: Inside get_jb_duties Function' . $e->getMessage(); } }
As of now the total job responses are under 15, with multiple (random) items in the other tables..
thanx all