使用codeigniter将row
我目前在一个网络应用程序上有一个功能,我正在建立一个求职者可以查看他们申请的工作,非常简单。
当它们“应用”时,该应用程序存储在数据库表'applicati'中,并带有'job_id'列,该列存储来自'jobs'数据库表的作业的'id'。
目前,我能够拉出所述求职者所做的每个应用程序。
但是,我无法遍历每个应用程序并到与该应用程序对应的作业,然后将row_array()添加到更大的数组中,然后我将使用foreach循环输出作业。
基本上我问我如何将一个数组添加到一个数组,然后输出完整的数组?
appliedfor.php (COTROLLER)
$applicati_query = $this->db->get_where( 'applicati', array('jobseeker_profile_id' => $user['id']) ); $applicati = $applicati_query->result_array(); $data[] = array(); foreach ($applicati as $application) { $job_id = $application['job_id']; $data['job'] = $this->db->get_where('jobs', array('id' => $job_id))->row_array(); $data['jobs'] .= $data['job']; } $data['jobs']; $this->load->view('header'); $this->load->view('appliedfor', $data);appliedfor.php (VIEW)
foreach ($jobs as $job) { $single_job_id = $job['id']; echo "<br>"; echo form_open('job/view' . '" id="eachJob'); echo "<div id=\"leftContain\" class=\"floatLeft\">"; echo "<h4 class=\"green\">" . $job['role'] . "</h4>"; echo "<div class=\"italic\"><div class=\"blue floatLeft\">" . $job['company'] . " </div><div class=\"floatLeft\">in</div><div class=\"blue floatLeft\"> " . $job['location'] . "</div></div><br><br>"; echo "</div>"; echo "<div id=\"rightContain\" class=\"floatLeft\">"; echo "<input type=\"hidden\" name=\"job_id\" value=\"" . $single_job_id . "\">"; echo form_submit('submit' . '" class="jobButton floatRight"', 'View Job'); echo "</div>"; echo form_close(); }我目前得到2个错误:未定义的索引:作业和错误在这一行显然是foreach中控制器中的$data['jobs'] 。
另一个错误是视图文件中的foreach,但这基本上是由第一个错误触发的。
谢谢你的帮助。
I currently have a function on a web app which I'm building where a jobseeker can view the jobs they have applied for, very simple.
When they "apply" this application is stored in the database table 'applicati' with a 'job_id' column which stores the 'id' of the job from the 'jobs' database table.
At the moment I am able to pull each application the said jobseeker has made.
Though, I am unable to loop through each application and find the job which corresponds to that application and then add the row_array() to larger array which I will then output the jobs with a foreach loop.
Essentially I am asking how do I add an array to an array and then output the full array?
appliedfor.php (COTROLLER)
$applicati_query = $this->db->get_where( 'applicati', array('jobseeker_profile_id' => $user['id']) ); $applicati = $applicati_query->result_array(); $data[] = array(); foreach ($applicati as $application) { $job_id = $application['job_id']; $data['job'] = $this->db->get_where('jobs', array('id' => $job_id))->row_array(); $data['jobs'] .= $data['job']; } $data['jobs']; $this->load->view('header'); $this->load->view('appliedfor', $data);appliedfor.php (VIEW)
foreach ($jobs as $job) { $single_job_id = $job['id']; echo "<br>"; echo form_open('job/view' . '" id="eachJob'); echo "<div id=\"leftContain\" class=\"floatLeft\">"; echo "<h4 class=\"green\">" . $job['role'] . "</h4>"; echo "<div class=\"italic\"><div class=\"blue floatLeft\">" . $job['company'] . " </div><div class=\"floatLeft\">in</div><div class=\"blue floatLeft\"> " . $job['location'] . "</div></div><br><br>"; echo "</div>"; echo "<div id=\"rightContain\" class=\"floatLeft\">"; echo "<input type=\"hidden\" name=\"job_id\" value=\"" . $single_job_id . "\">"; echo form_submit('submit' . '" class="jobButton floatRight"', 'View Job'); echo "</div>"; echo form_close(); }I am currently getting 2 errors: Undefined index: jobs and the error is on this line apparently $data['jobs'] in the controller within the foreach.
The other error is the foreach within the view file but that is basically triggered by the first error.
Thanks for your help.
最满意答案
你是对的:
$data['jobs'] .= $data['job'];连接字符串,而不是数组,永远不会工作。
相反,尝试类似于:
$data['jobs'][] = $data['job'];构建一个作业数组,然后使用foreach()或任何最合适的输出
You are correct:
$data['jobs'] .= $data['job'];concatenates strings, not arrays, and will never work.
Instead, try something like:
$data['jobs'][] = $data['job'];to build up an array of the jobs, then output with a foreach() or whatever is most suitable
#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格
下一篇:SpringMVC面试问题
推荐阅读
留言与评论(共有 5 条评论) |
本站网友 有啥好看的电影 | 10分钟前 发表 |
然后使用foreach()或任何最合适的输出 You are correct | |
本站网友 回收公司 | 12分钟前 发表 |
$data['jobs'] .= $data['job']; concatenates strings | |
本站网友 顺差 | 9分钟前 发表 |
and will never work. Instead | |
本站网友 黑云压城城欲摧 | 2分钟前 发表 |
而不是数组 |