再次是我!我的代码问题是它只显示一条记录而不是两条记录。我已经尝试回显SQL语句并粘贴在PHPMyAdmin上并显示2条记录,但在我的结尾却没有。
这是我的控制器:
function index()
{
if($this->tank_auth->is_logged_in()):
$data['title'] = 'Tes : Home';
$data['record'] = $this->Profile_model->get_profile_by_id();
$ws = $this->Wall_model->get_user_posts();
foreach($ws as $w):
$data['cont'] = '<li class="profile-thread-post">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td width="75" class="valign-top">
<div id="post-avatar">
<img src="../../images/avatar.gif" width="74" height="74" />
</div>
</td>
<td width="15"> </td>
<td class="valign-top">
<div id="post-div">
<div>';
$data['cont'] .= '<span class="title oswald blue cap">'.$w->fname.'</span><span class="title oswald red cap">'.$w->lname.'</span>';
$data['cont'] .= '<p>'.$w->body.'</p>';
$data['cont'] .= '<br/><br />
<div class="floatLeft small-text grayLight">
Posted 2 hours ago
</div>
<div class="social-links alignRight">
</div>
</div>';
$pid = $w->id;
$comments = $this->Wall_model->get_user_comments($pid);
//if(count($comments) > 0 ):
$data['cont'] .= '<ul id="post-comments-div">';
foreach($comments as $c):
$data['cont'] .= '<li class="comment-entry">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td class="valign-top comment-avatar alignLeft" width="55">
<img src="../../images/avatar.gif" width="46" height="46" />
</td>
<td class="valign-top comment-post">
<div>
<span class="sub-title oswald blue cap">'.$c->fname.'</span><span class="sub-title oswald red cap">'.$c->lname.'</span>
</div>
<div class="small-text-11 comment-content">'.$c->comment;
$data['cont'] .= '</div>
<div class="comments-meta alignRight">
<span class="lgray small-text">Posted 2 hours ago</span>
<a href="#" class="uline like-link ">like</a>
</div>
</td>
</tr>
</table>
</li>';
endforeach;
$data['cont'] .= '</ul>';
//endif;
$data['cont'] .= '</td></tr></table></li>';
endforeach;
$this->load->view('profile/index', $data);
else:
$this->session->set_flashdata('message', '<div class="error centerText">You are not logged in</div>');
redirect('auth/login');
endif;
}
这是我的模特:
function get_user_posts()
{
$uid = $this->tank_auth->get_user_id();
$query = $this->db->query("SELECT a.*, b.* from user_profiles a inner join user_statuses b on a.user_id = b.user_id where b.user_id = $uid order by posted_date DESC");
return $query->result();
}
function get_user_comments($pid)
{
$result = $this->db->query("SELECT * FROM user_statuses a
INNER JOIN user_status_comments c ON a.id = c.post_id
INNER JOIN user_profiles b ON b.user_id = c.user_id where a.id = $pid");
return $result->result();
}
在我的表上,SQL语句显示 | USER_ID | POST_ID |身体| 1 1 S. 1 2 H
答案 0 :(得分:2)
尝试:
$data['cont'] = ''; //then foreach loop foreach($ws as $w): //then $data['cont'] .= '<li class="profile-thread-post">...