Welcome Guest, Not a member yet? Register   Sign In
second query based on first query
#2

[eluser]sniperscope[/eluser]
I solved my problem.
I am posting solution and hope it might help to someone else too.

Code:
class Model_System extends CI_Model
{
function Category()
{
  $dsp = "";
  $sql = "SELECT price_id, price_name, price_remark FROM price_master ORDER BY price_id ASC";
  $query = $this->db->query($sql);
  
  if($query->num_rows > 0)
  {
   $row = $query->result_array();
   foreach($row as $row)
   {
    $dsp .= '
    <table class="system">
     <tr><td colspan="2" class="tdTitle">' .$row['price_name']. '</td></tr>';
    
    $sub_category = "SELECT price_child_title, price_child_price FROM price_child WHERE price_master_id = '" .$row['price_id']. "' ORDER BY price_child_id DESC";
    $sub_category = $this->db->query($sub_category);
    if($sub_category->num_rows > 0)
    {
     $sub = $sub_category->result_array();
    
     foreach($sub as $sub)
     {
      $dsp .= '
      <tr><th>' .$sub['price_child_title']. '</th><td>' .$sub['price_child_price']. '円</td></tr>';
     }
    }
    
     $dsp .= '
     <tr><td colspan="2" class="tdBiko">' .$row['price_remark']. '</td></tr>
    </table>';
   }
  }
  $query->free_result();
  return $dsp;
}


Messages In This Thread
second query based on first query - by El Forum - 12-16-2012, 10:02 PM
second query based on first query - by El Forum - 12-17-2012, 02:49 AM
second query based on first query - by El Forum - 12-21-2012, 07:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB