开发者

CodeIgniter: How execute a select query with where clause and return the result as table view

开发者 https://www.devze.com 2022-12-21 08:07 出处:网络
In codeigniter framework How I execute a select query with where clause and put the value into a table and return the table??

In codeigniter framework How I execute a select query with where clause and put the value into a table and return the table??

example开发者_StackOverflow中文版:

function abc($input)
{
  $query=........where name='.$input.';
........
.......

return table;
}

...........how I do it?


Tom has a very good point. All of this is in the User Guide, but just to direct you to which bits, try this super-fun three step challenge:

  1. Creating queries with ActiveRecord
  2. Generating Query Results
  3. HTML Table Class

Tadaaaaa! Magic. In the future, have a shufty around the CodeIgniter User Guide: Table of Contents.


i already prepare this things pls see the code below:

function getSearchResults ($function_name, $description = TRUE)
{
     $this->db->like('songName', $function_name);
    $this->db->orderby('songName');
    $query = $this->db->get('tbl_rbt');
    if ($query->num_rows() > 0) 
    {
        $output = '<table width="800" border="1" class="output_table">';
        foreach ($query->result() as $function_info) 
        {
            if ($description) 
            {               
                $output .= '<tr ><td>'.$function_info->songName.'</td>';
                $output .= '<td>'.$function_info->albumName.'</td>';                    
                $output .= '<td>'.$function_info->artistName.'</td></tr>';

            } 
            else 
            {
                $output .= '<tr>'.$function_info->songName.'</tr>';
            }
        }
        $output .= '</table>';
        return $output;
    } 
    else 
    {
        return '<p>Result not found.</p>';
    }
  }

thanks to all riad


the userguide is very helpful for these types of basic questions

http://codeigniter.com/user_guide

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号