[英]Displaying user info on a page using their ID
Im trying to create a dynamic web page in php and mysql. 我试图在php和mysql中创建一个动态网页。 I have the below code on the profile.php page. 我在profile.php页面上有以下代码。 The issue im having is on the "while" line im not sure how i would go about getting the information from the DB. 我所遇到的问题是在“ while”行上,我不确定我将如何从数据库获取信息。 I want to display details like email, country First name, etc. Any help appreciated. 我想显示详细信息,例如电子邮件,国家/地区的名字等。任何帮助表示赞赏。 Thanks in advance! 提前致谢! CODE: 码:
$userid = (isset($_GET['id']) ? $_GET['id'] : NULL);
if ($userid) {
$userinfo = $DB->query_first("SELECT * FROM `users` WHERE `id` = '$userid'");
print_r($userinfo);
}
//{
while($row = sql_fetch_assoc($DB)){
echo'<div class="container">
<div class="jumbotron" align="block">';
echo $row['first_name'];
echo $row['last_name'];
echo $row['country'];
echo $row['username'];
echo'</div>';
echo'</div>';
}
Try by using this 尝试使用此
<?php
$userid = (isset($_GET['id']) ? $_GET['id'] : NULL);
if ($userid) {
$userinfo = $DB->query_first("SELECT * FROM `users` WHERE `id` = '$userid'");
print_r($userinfo);
?>
<table>
<tr>
<td>First Name</td>
<td><?=$userinfo['first_name']?></td>
</tr>
<tr>
<td>Last Name</td>
<td><?=$userinfo['last_name']?></td>
</tr>
............
............
</table>
<?php } ?>
do not use null use a empty string "" that is what you want sql well do nothing with an empty string it is just white space, enough about sql injection attacks wtf ever topic i enter. 不要使用null使用空字符串“”,这是您想要sql很好使用的空字符串,它只是空白,对于我所输入的主题进行的SQL注入攻击已经足够了。 actually make it equal to wither where userid='$userid' or "". 实际上使它等于在userid ='$ userid'或“”时枯萎。 there is only one row so the while statement is redundant just row = mysql_fetch_array. 只有一行,所以while语句是多余的,只是row = mysql_fetch_array。
You can try something like this: 您可以尝试如下操作:
<?php
$userid = (isset($_GET['id']) ? $_GET['id'] : NULL);
if ($userid) {
$userinfo = $DB->query_first("SELECT * FROM `users` WHERE `id` = '$userid'");
print_r($userinfo);
echo'
<div class="container">
<div class="jumbotron" align="block">
'.$userinfo['first_name'].' <br>
'.$userinfo['last_name'].' <br>
'.$userinfo['country'].' <br>
'.$userinfo['username'].' <br>
</div>
</div>';
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.