dp709369831 2017-07-25 08:16
浏览 36
已采纳

无法在codeigniter php中显示所选的文本数据

Clicking on a text displaying that text in url but unable to show that text in view file.

View:

<div class="applynow"><a href="<?php echo base_url();?>career/apply/<?php echo $r->job_name;?>" class="applyforjob">Apply Now</a></div>

Clicking on the apply now button displaying the job name in URL. But The job name is not dislaying in view file.

Controller:career/apply

function apply()
{
    $this->load->model('career_model');
    $data['records2']= $this->career_model->getcareerdatas($this->uri->segment(3));
    $data['mainpage']='apply';            
    $this->load->view('templates/template',$data);
}

Career Model:

function getcareerdatas($id)
{
    $this->db->select('jobs_list.*');       
    $this->db->from('jobs_list');
    $this->db->where(array('jobs_list.job_name'=>$id));
    $q=$this->db->get();        
    if($q->num_rows()>0)
      {
    return $q->result();
        }
    else
    {
    return false;
    }
}

View:

<form name="applynow"  id="applynow" enctype="multipart/form-data" method="post"  action="<?php echo base_url();?>apply/applynow">

            <div class ="applyus">  
            <?php if(isset($records2) && is_array($records2)):?>
            <?php foreach ($records2 as $r):?>              
            <span class="digit"><?php echo $r->job_name ;?></span>
            <?php endforeach;endif;?>

                    <div class="applyfullname contactname">
                        <label for="fullname"><font color="black">Full Name</font><span class="mandatory"><font color ="red">*</font></span></label>
                        <input type="text" class="form-control names" name="fullname" id="fullname " value="<?php echo set_value('fullname');?>" placeholder="Full Name">   
                        <?php echo form_error('fullname', '<div class="error">', '</div>'); ?>
                    </div>  

                    <div class="applynowemail contactemail">
                    <label for="email"><font color="black">Email</font><span class="mandatory"><font color ="red">*</font></span></label>
                        <input type="email" class="form-control emails" id="email" name="email" value="<?php echo set_value('email');?>" placeholder="Email" >
                        <?php echo form_error('email', '<div class="error">', '</div>'); ?>                         
                    </div>

Clicking on apply now button it will open another page in that page it is not displaying the job name.

MYSQL:

+---------+--------------------+--------------------+-----------------+
| jobs_id |      job_name      |     jobs_name      | job_description |
+---------+--------------------+--------------------+-----------------+
|       1 | Junior QA Enginner | Junior_QA_Enginner | Description     |
|       2 | Junior Engineer    | Junior_Enginner    | Description     |
+---------+--------------------+--------------------+-----------------+
  • 写回答

2条回答 默认 最新

  • douyuliu9527 2017-07-25 09:25
    关注

    First view is like (take job_id instead job_name in url) :

    <div class="applynow"><a href="<?php echo base_url();?>career/apply/<?php echo $r->jobs_id;?>" class="applyforjob">Apply Now</a></div>
    

    Now, after clicking on this your controller be like (no need of segment, you can take value of querystring as parameter of function in codeigniter) :

    function apply($job_id)
    {
        $this->load->model('career_model');
        $data['records2']= $this->career_model->getcareerdatas($job_id);
        $data['mainpage']='apply';            
        $this->load->view('templates/template',$data);
    }
    

    Then your model is (change your query to compare with job_id instead job_name) :

    function getcareerdatas($id)
    {
        $this->db->select('jobs_list.*');       
        $this->db->from('jobs_list');
        $this->db->where('jobs_list.jobs_id', $id);
        $q = $this->db->get();        
    
        return $q->result();
    }
    

    Keep the view as it is. If you get matching record with your $jobs_id then you definitely get data in $records2.

    Try this solution.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题