gpt4 book ai didi

php - 根据用户显示mysql数据库的特定数据

转载 作者:行者123 更新时间:2023-11-30 00:43:02 25 4
gpt4 key购买 nike

我试图做到这一点,以便如果用户查看他们的页面,他们可以看到他们正在处理或已经完成的作业。然后我想让他们在查看另一个用户页面时可以看到他们创建的项目。

    $my_id = $_SESSION['user_id'];
$frnd_query = mysql_query("SELECT user_one, user_two FROM frnds WHERE user_one = '$my_id' OR user_two = '$my_id'");
while($run_frnd = mysql_fetch_array($frnd_query)) {
$user_one = $run_frnd['user_one'];
$user_two = $run_frnd['user_two'];
if($user_one == $my_id) {
$user = $user_one;
} else {
$user = $user_two;
}
$username = getuser($user, 'username');
echo "<a href = 'my_ideas.php?user=$user' class = 'list' style=display:block>Ideas</a>";

?>
<ul>

<li><a href = '#my_links'>Linked Ideas</a></li>
<li><a href = '#idea_chemistry'>My Idea Chemistry</a></li>
<li><a href = 'settings.php'>Profile Settings</a></li>>
</ul>
</div>

<div id = 'my_projects'>

<?php


if($user != $_SESSION['user_id']) {
$ideas_sql = "SELECT * FROM projects WHERE user_id = $username";
$query = mysql_query($ideas_sql) or die(mysql_error());
$rsIdeas = mysql_fetch_assoc($query);

do {
?>
<h2><a href = 'edit_post.php?id=<?php echo $rsIdeas['id']; ?>'><?php echo $rsIdeas['name']; ?></a></h2>

<?php echo $rsIdeas['keywords']; ?></p>
<p><?php echo $rsIdeas['description']; ?></p>
<?php } while ($rsIdeas = mysql_fetch_assoc($query));


} else {

$ideas_sql = "SELECT * FROM projects WHERE user_id = $my_id";
$query = mysql_query($ideas_sql) or die(mysql_error());
$rsIdeas = mysql_fetch_assoc($query);


do {
?>
<h2><a href = 'edit_post.php?id=<?php echo $rsIdeas['id']; ?>'><?php echo $rsIdeas['name']; ?></a></h2>

<p><?php echo $rsIdeas['keywords']; ?></p>

<p><?php echo $rsIdeas['description']; ?></p>
<?php } while ($rsIdeas = mysql_fetch_assoc($query));
}
?>
<?php
}

?>

我已经用谷歌搜索了这个并在这里搜索了相关问题,但我似乎找不到任何可以帮助解决我的问题的内容。

最佳答案

这基本上是一个代码审查问题。 SO 网络上还有另一个站点,您可以在其中提出此类问题。尽管您应该表明您具有一定的编码知识。

我不确定为什么没有起始 PHP 标签,但这是第一部分。

<?php

$my_id = $_SESSION['user_id'];
$frnd_query = mysql_query("SELECT user_one, user_two FROM frnds WHERE user_one = '".$my_id."' OR user_two = '".$my_id."'");
while($run_frnd = mysql_fetch_array($frnd_query)) {
$user_one = $run_frnd['user_one'];
$user_two = $run_frnd['user_two'];
if($user_one == $my_id) {
$user = $user_one;
} else {
$user = $user_two;
}
$username = getuser($user, 'username');
echo "<a href = 'my_ideas.php?user='".$user."' class = 'list' style=display:block>Ideas</a>";

?>
<ul>

<li><a href = '#my_links'>Linked Ideas</a></li>
<li><a href = '#idea_chemistry'>My Idea Chemistry</a></li>
<li><a href = 'settings.php'>Profile Settings</a></li>>
</ul>



<div id = 'my_projects'>

<?php


if($user != $_SESSION['user_id']) {
$ideas_sql = "SELECT * FROM projects WHERE user_id = '".$username."'";
$query = mysql_query($ideas_sql) or die(mysql_error());
$rsIdeas = mysql_fetch_assoc($query);

do {
?>
<h2><a href = 'edit_post.php?id=<?php echo $rsIdeas['id']; ?>'><?php echo $rsIdeas['name']; ?></a></h2>

<?php echo $rsIdeas['keywords']; ?></p>
<p><?php echo $rsIdeas['description']; ?></p>
<?php } while ($rsIdeas = mysql_fetch_assoc($query));


} else {

$ideas_sql = "SELECT * FROM projects WHERE user_id ='".$my_id."'";
$query = mysql_query($ideas_sql) or die(mysql_error());
$rsIdeas = mysql_fetch_assoc($query);


do {
?>
<h2><a href = 'edit_post.php?id=<?php echo $rsIdeas['id']; ?>'><?php echo $rsIdeas['name']; ?></a></h2>

<p><?php echo $rsIdeas['keywords']; ?></p>

<p><?php echo $rsIdeas['description']; ?></p>
<?php } while ($rsIdeas = mysql_fetch_assoc($query));
}
?>
<?php
}

?>

问题:这是一个自定义函数getuser()吗?

关于php - 根据用户显示mysql数据库的特定数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21616783/

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