簡體   English   中英

從數據庫獲取鏈接

[英]To get a link from database

嗨,我當前正在使用codeigniter,下面我附了完整的代碼。 當我運行此即時消息時,我正在從數據庫獲取數據,但是我希望URL字段為link.How做到這一點。 這是我的控制器:

public function ajaxsearch()
{
   if(is_null($this->input->get('id')))
    {
        $this->load->view('input_view');    
    }
    else
    {
        $this->load->model('Infomodel'); 

        $data['Infotable']=$this->Infomodel->Infotable($this->input->get('id')); 

        $this->load->view('output_view',$data);
    }
}

下面是模型:

class Infomodel extends CI_Model 
{


    function Infotable($search)
    {

        $query = $this
                ->db
                ->select('*')
                ->from('Info_table')
                ->like('NAME',$search)
                ->or_like('URL',$search)
                ->get();

        if($query->num_rows()>0)
        {
            return $query->result(); 
        }
        else
        {
            return null;
        }

    }

}

和兩個視圖:一個是input_view

另一個是output_view:

if(!empty($Infotable ))  
{

    $output = '';
    $outputdata = '';  
    $outputtail ='';

    $output .= '<div class="container">
           <div class="table-responsive">
           <table class="table table-bordered">
            <thead>
                  <tr>
          <th>No</th>
                      <th>Name</th>
                      <th>Url</th>
                      <th>Tags</th>
          </tr>

           </thead>
           <tbody>
           ';

    foreach ($Infotable as $objects)    
    {   
        $outputdata .= ' 

            <tr> 
            <td >'.$objects->id.'</td>
            <td >'.$objects->name.'</td>
            <td>'.$objects->url.'</td>   
                    <td>'.$objects->tags.'</td>
            </tr> 

    ';
    //  echo $outputdata; 

    }  

    $outputtail .= ' 
                 </tbody>
                 </table>
                 </div>
                 </div> ';

    echo $output; 
    echo $outputdata; 
    echo $outputtail; 
}

else  
{  
    echo 'Data Not Found';  
}

先謝謝您的幫助。

嘗試在表格數據中使用標簽。

<td> <a heref="'.$objects->url.'">'.$objects->url.'</a></td>

如果您想讓用戶點擊該網址,則只需更改以下行即可:

<td>'.$objects->url.'</td>

像這樣:

<td><a href="'.$objects->url.'">'.$objects->url.'</a></td>

這將在表格單元格中創建一個鏈接,該鏈接會將您發送到該鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM