Good day! Please help me combine several requests and display them in one Foreach.

Example:

$this->db->where('work !=','yes'); $rg1 = $this->db->get('works'); $r1 = $rg1->result(); $this->db->where('image','blank.jpg'); $rg2 = $this->db->get('photos'); $r2 = $rg2->result(); $html = ""; foreach($r1 as $rw){ $html .= "<li class='notifications'> <a href='".$rw->slug."'>".$rw->title." <br>Нет графика </a> </li>"; } foreach($r2 as $rp){ $html .= "<li class='notifications'> <a href='".$rp->link."'>".$rp->name." <br>Нет фото </a> </li>"; } 

In the example above, there are 2 requests, after 2 outputs (foreach). How can I make two (or more) queries to the database, and then merge them into one foreach, while taking into account that the information received and the output template can be different ($ rw-> title ** $ rp-> name, etc.)?

thank

  • As far as I know, two queries to different tables are not combined into one. - Oboroten
  • I meant that in practice such associations are not used. - Oboroten
  • You just need to do something like notifications. But that they were in one foreach. So everything works, but sorting does not work. In this case, at the top of the list displays everything where there is no graphics, and at the end of the list where there is no photo. And you need to alternate, depending on the date - kate
  • to you in words? do something like this select slug, 'Нет графика' text from table1 union select link slug, 'Нет картинки' text from table2 Get a common array, sort and output - splash58

0