Hello I have an array that looks like this after passing it through uksort()
Array
(
[3] => Array
(
[job_id] => 4
[job_title] => Supercar Test Driver
[company_name] => McLaren
[logo_small] => small_mclaren001.png
[logo_large] => large_mclaren002.png
[employer_id] => 3
)
[2] => Array
(
[job_id] => 3
[job_title] => Recruitment Consultant - Driving
[company_name] => MoovJob.com
[logo_small] => small_rac001.png
[logo_large] => large_rac002.png
[employer_id] => 2
)
[1] => Array
(
[job_id] => 5
[job_title] => Postal Worker / Post Person
[company_name] => Royal Mail
[logo_small] => small_royalmail001.png
[logo_large] => large_royalmail002.png
[employer_id] => 4
)
[0] => Array
(
[job_id] => 6
[job_title] => Another Job
[company_name] => MoovJob.com
[logo_small] => small_rac001.png
[logo_large] => large_rac002.png
[employer_id] => 2
)
)
However if in my SQL that returns this array I add GROUP BY company_name the final entry in the array dissapears, what I am trying to achieve is to place the job title under the company name, but only show the company name once, something similar to this,
Company Name 1
Job Title 1
Job Title 2
Job Title 3Company Name 2
Job Title 4Company Name
Job Title 5 Job Title 6
I am trying to achieve this, by doing the followng in my view, however I can only show one vacancy, what am I doing wrong?
<?php $oldemp = "";?>
<?php foreach($jobs as $key => $value) : ?>
<?php if ($oldemp != $value['company_name']) : ?>
<?php $oldemp = $value['company_name']; ?>
<section class="employer">
<div class="job_holder">
<img src="<?php echo base_url(); ?>media/uploads/users/<?php echo $value['logo_large']; ?>" width="198" height="148" alt="<?php echo $value['company_name']; ?>"/>
<dl>
<dt><?php echo count($key); ?></dt>
<dd>Matches</dd>
</dl>
<?php endif;?>
<span> + <a href="/jobwall/getjob/<?php echo $value['job_id']; ?>"><?php echo $value['job_title']; ?></a></span>
</div>
</section>
<?php endforeach; ?>
function jobcmp($job1, $job2)
{
return strcmp($job1['company_name'], $job2['company_name']);
}
Although it would be possible to display the data using your approach I normally find it much more straightforward to create a second array in a more convenient format:
this creates a new array using the company name as the key and that company’s jobs in a nested array as the value, giving you something like this:
it is then much easier to loop through this array and display: