显示用户个人资料页面PHP [英] Displaying a user profile page PHP

查看:374
本文介绍了显示用户个人资料页面PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在建立社交网络.我正在使用以下代码显示所有注册用户. 有更好的方法吗?

I'm currently in the process of making a social network. I'm am displaying all registered users with the following code. Is there a better way of doing this?

<?php 
$query = $db->query("SELECT * from members");

while($r = $query->fetch()) {
    echo '<div class="col-sm-6 col-md-6 col-lg-3 membersGrid">';
    echo '<div class="profileThumb">';
    echo  '<img width="130" height="130" src="'.$r['profile_pic'].'"/><br>';
    echo $r['username'], '<br>';
    echo  $r['country'], '<br>';
    echo '<a class="viewProfile" href="profile.php"><button>View Profile</button></a>';
    echo '</div>';
    echo '</div>';

}
  ?>

我正在尝试为每个用户创建指向个人资料页面的链接.当前,每个链接都在上述while循环内,但是,我不确定如何链接到相关的个人资料页面.我猜我必须在URL后面附加一个变量.任何指导将不胜感激.

I'm trying to create a link to the individual profile pages for each users. Currently each link is within the above while loop, however, I'm a little uncertain of how to link to the relevant profile page. I'm guessing I have to append a variable to the URL. Any guidance would be greatly appreciated.

    echo '<a class="viewProfile" href="profile.php"><button>View Profile</button></a>';

推荐答案

这取决于您的profile.php页面如何处理GET变量,该变量确定了所显示人员的个人资料.假设该变量名为id,并且您在 members 表中也有一行也称为id(用作唯一键),那么锚标记将如下所示:

It would depend on how your profile.php page is handling the GET variable that determines the profile of the person you are showing. Let's say that the variable is called id and that you have a row in your members table also called id (which acts as the unique key), then your anchor tag would look like:

echo '<a class="viewProfile" href="profile.php?id=' . $r['id']. '"><button>View Profile</button></a>';

这篇关于显示用户个人资料页面PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆