gpt4 book ai didi

html - 显示 View 文件中的特定数据

转载 作者:行者123 更新时间:2023-11-29 23:17:11 24 4
gpt4 key购买 nike

这里我有一个 View 文件,我可以在其中看到信息。它工作得很好。但我想将 View 视为登录者。假设如果男性登录,他将看到女性信息。女性就像男性一样。我该怎么做?我正在 codeigniter 中这样做。

main.php// Controller

public function viewStd(){

$data=array();
$this->load->model('signup_model');
$data['query1']=$this->signup_model->viewData();
$this->load->view('view_std',$data);


}

signup_model.php//模型

 public function viewData(){

$query=$this->db->get('std_info');
return $query->result();


}

view.php// View

    <?php
session_start();

if(!$this->session->userdata('id')){ //Here is the session start.
redirect("login/checkLogin");}
?>
<table border="1">
<tr><td>Name</td><td>Phone</td><td>Email</td></tr>
<?php
foreach ($query1 as $student){
//echo "<pre>";
//print_r($student);
?>
<tr><td><?php echo $student->name?></td><td><?php echo $student->phone?></td>
<td><?php echo $student->email?></td>
</tr>
<?php }?>
</table>

最佳答案

你说

i want to show data as opposite gender.If male person logged in he will see female information.if female logged in she will see male information.

在 Controller 中执行此操作。检查性别,然后调用适当命名的方法。

if( $person->gender == 'male'){

$this->showFemales($query1) ; }

else { $this->showMales($query1) ; }

您的 session 设置和检查应该在 Controller 中进行,而不是在 View 中。

关于html - 显示 View 文件中的特定数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27675179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com