gpt4 book ai didi

php - 如何在未登录的情况下根据url id放置在浏览器地址上来获取特定数据表

转载 作者:行者123 更新时间:2023-11-30 00:14:08 24 4
gpt4 key购买 nike

我是一个新人,刚刚学习,我对从表到 url id 获取数据表感到困惑,我想在写入 url 时从表中获取数据,例如 localhost/index.php?=user='username' 并且表将根据 url 用户名显示

这里是表格示例

内容表

code_content    |  judul_content  |  deskripsi  |  nama_lengkap
2 abc tes1 john
3 efg tes2 gerald
4 hij tes3 john

用户表

username   |  password  | nama_lengkap
user1 123 john
user2 234 gerald

当我写这个 url localhost/index.php?=user=user2 时,我希望显示此输出

**

judul_content = "efg" 
nama_lengkap = "gerald"

**

<?php 
$koneksi = mysql_connect("localhost","root","1234");
mysql_select_db("my_db");
$hal = 0;
if(isset($_GET['page'])){
$page = $_GET['page'];
}else{
$page = 1;
}

$limit = 2;
$offset = ($page - 1)*$limit;
$hasil = mysql_query("select * from content order by code_content desc limit $offset,$limit;");
$get_total = mysql_query("select count(*) as total from content");
$total_artikel = 0;
while($h_total = mysql_fetch_array($get_total)){
$total_artikel = $h_total['total'];
}
$total_page = ceil($total_artikel/$limit);
?>

<?php while($data = mysql_fetch_array($hasil)){ ?>

<h2><a href="index.php?page=full&kode=<?php echo $data["code_content"]; ?>" style="text-decoration:none;">
<?php echo $data["judul_content"]; ?></a></h2>
<?php echo $data["tanggal"]; ?> by <a href="#" target="_blank"><?php echo $data["nama_lengkap"]; ?></a>
<div id="posts-list" class="cf">
<div class="right" style="float:left; text-align:justify; width:100%;">
<?php
echo implode(array_slice(explode(" ",$data["content"]),0,75)," ").".....";
?><br /><br />
<a href="index.php?page=full&kode=<?php echo $data["code_content"]; ?>">Continue reading...</a> <!--| <a href="#">Comments (60)</a>-->
</div>
<div class="cleaner"></div>
</div>
<?php } ?>
<div>
<?php if($page > 1){ ?>

如何在没有登录的情况下根据url用户显示表格谢谢

最佳答案

由于您尝试从 2 个表中检索数据,因此您必须在两个表之间建立关系(将内容中的 user_id 作为外键传递),然后您可以借助 URL 传递的值轻松检索数据。

用户表

id | username   |  password  | nama_lengkap
1 user1 123 john
2 user2 234 gerald

内容表

user_id | kode_content    |  judul_content  |  deskripsi  |  nama_lengkap
1 2 abc tes1 john
2 3 efg tes2 gerald

localhost/index.php?=user='用户名'

if(isset($_GET['user'])) {
$user_name = $_GET['user'];

$check_user = "SELECT username FROM user WHERE username = '$user_name' LIMIT 1";
if(!empty($check_user))
{
$user_data = "SELECT contents.judul_content, users.nama_lengkap
FROM users
INNER JOIN contents
ON users.id=contents.user_id
WHERE users.username = '$check_user'";
print_r ($user_data);
}else{
echo "No User Found."
}

}

关于php - 如何在未登录的情况下根据url id放置在浏览器地址上来获取特定数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23796909/

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