Sundar Nivash
Sundar Nivash

Reputation: 306

how to fetch the a record from a table and display them in another view

I have a table named settings with fields like id,tax1,tax2 etc., and i created a view named service.view i need to get the tax1 value from settings table and display a label in service.view file. how could i do this? can some one help me code... this is my table structure

CREATE TABLE IF NOT EXISTS `service_settings` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `company_name` varchar(30) NOT NULL,
  `company_logo` varchar(50) NOT NULL,
  `company_tax11` varchar(20) NOT NULL,
  `company_tax12` varchar(20) NOT NULL,
  `company_tax13` double NOT NULL,
  `company_tax14` double NOT NULL,
  `company_tax21` varchar(20) NOT NULL,
  `company_tax22` varchar(20) NOT NULL,
  `company_tax23` double NOT NULL,
  `company_tax24` double NOT NULL,
  `company_tax31` varchar(20) NOT NULL,
  `company_tax32` varchar(20) NOT NULL,
  `company_tax33` double NOT NULL,
  `company_tax34` double NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

I am using codeigniter and mysql database I need to get a single record from this table and display it in a service.view

Upvotes: 0

Views: 49

Answers (1)

Abdulla Nilam
Abdulla Nilam

Reputation: 38584

Alter this code as you want. This display your data in database as well

in model

<?php
    public function get_service()
    {
        $query= $this->db->query("SELECT * FROM user service_settings");
        $result= $query->result_array();
        return $result;
    }
?>

in controller

<?php
    public function login()
        {

            $data['table'] =  $this->Model_Name->get_service();

            $this->load->view('service');//load your relevant view

        }
?>

in view

<table>
    <tr>
        <th>company_name</th>
        <th>company_tax11</th>
        <th>company_tax12</th>
        <th>company_tax13</th>
        <th>company_tax14</th>
    </tr>       
    <?php
    foreach ($table as $new_tbale) 
    {
        ?>
        <tr>
            <td>$new_tbale['company_name']</td> 
            <td>$new_tbale['company_tax11']</td>    
            <td>$new_tbale['company_tax12']</td>    
            <td>$new_tbale['company_tax13']</td>    
            <td>$new_tbale['company_tax14']</td>
        </tr>                   
        <?php
    }
        ?>      
</table>

Edit 01

<?php
    public function get_service()
    {
        $query= $this->db->query("SELECT company_tax11 FROM user service_settings");
        $result= $query->result_array();
        return $result;
    }
?>

Upvotes: 1

Related Questions