CakePhp verbinden drei Tabellen wiederholt das Array -ElementPhp

PHP-Programmierer chatten hier
Guest
 CakePhp verbinden drei Tabellen wiederholt das Array -Element

Post by Guest »

Ich habe drei Tabellen Jobs ,

Code: Select all

tags
und job_tags . Ich trete den Tabellen in Job.php < /code> modell wie unten an: < /p>

Code: Select all

$job_cond = array('Job.status = 1');
if($job_id != NULL){
$condition['Job.id'] = $job_id;
array_push($job_cond,"Job.id = $job_id");
}
$tag_cond = "";
if($tag_id != NULL){
$tag_cond = array("Tag.id = $tag_id");
}

$options = array(
'fields' => array('Job.*', 'Tag.*'),
'conditions' => $job_cond,
'order' => array('Job.added_on DESC'),
'recursive' => -1,
'joins' =>
array(

array(
'table' => 'tags',
'alias' => 'Tag',
'type' => 'inner',
'conditions' => $tag_cond,
),
array(
'table' => 'job_tags',
'alias' => 'JobTag',
'type' => 'inner',
'conditions' => array('JobTag.job_id = Job.id','JobTag.tag_id = tag.id'),
)
)
);
$res = $this->find('all', $options); echo count($res);
Das Ergebnis zeigt das Array an, aber für jedes Tag_ID zeigt das Ergebnis den Auftrag für jedes Tag an. Das heißt, das Array ist etwas wie unten: < /p>

array(
(int) 0 => array(
'Job' => array(
'id' => '7',
'title' => 'th fgh fghfgh',
'description' => 'fgh fh ffgh',
'email' => '[email protected]',
'min_experience' => '2',
'max_experience' => '3',
'freshers_apply' => 'No',
'phone' => '56546546',
'address' => 'df',
'posted_on' => '2015-02-27',
'status' => '1',
'added_on' => '2015-02-27 16:57:05'
),
'Tag' => array(
'id' => '3',
'name' => 'Sales',
'status' => '1'
)
),
(int) 1 => array(
'Job' => array(
'id' => '5',
'title' => 'dfg dfgdfg ',
'description' => 'dfg dfgdfg',
'email' => '[email protected]',
'min_experience' => '2',
'max_experience' => '3',
'freshers_apply' => 'No',
'phone' => '345345345',
'address' => 'df',
'posted_on' => '2015-02-27',
'status' => '1',
'added_on' => '0000-00-00 00:00:00'
),
'Tag' => array(
'id' => '5',
'name' => 'Database',
'status' => '1'
)
),
(int) 2 => array(
'Job' => array(
'id' => '5',
'title' => 'dfg dfgdfg ',
'description' => 'dfg dfgdfg',
'email' => '[email protected]',
'min_experience' => '2',
'max_experience' => '3',
'freshers_apply' => 'No',
'phone' => '345345345',
'address' => 'df',
'posted_on' => '2015-02-27',
'status' => '1',
'added_on' => '0000-00-00 00:00:00'
),
'Tag' => array(
'id' => '1',
'name' => 'IT',
'status' => '1'
)
)
< /code>

Ich möchte also wissen, wie ich den doppelten Job für verschiedene Tag -IDs entfernen kann < /p>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post