追随其他用户
接下来可以将更多东西添加到 functions.php 文件中。这里需要一个 show_users() 函数,该函数可以返回系统中所有用户的一个列表。后面将使用这个函数填充一个用户列表。
清单 10. show_users() 函数
有了 show_users() 函数之后,接下来可以创建一个 users.php 文件,该文件将运行这个函数,并显示系统中所有用户的一个列表,对于每个用户,在用户名的旁边都有一个 follow 链接。
清单 11. 运行 show_users() 函数的 users.php 文件
为了访问这个用户列表,在 index.php 文件中表单的上方添加一个到 users.php 的链接:
现在有了一个易于使用的用户名列表,每个用户名旁有一个 follow 链接。
百家CMS微商城
百家CMS微商城从诞生开始,就坚持着简单实用的原则,基于目前最流行的WEB2.0的架构(php+mysql),拥有成熟、稳定的微电商技术解决方案。基于完整的会员等级制度,完善的微商城购物流程,订单管理、优惠券、搜索、购物车等功能。采用跨平台机制,可同时对接微信公众号平台和支付宝服务窗,兼容微博、手机QQ等平台;丰富的支付方式、支持微信支付、支付宝支付、货到付款、余额支付、网银支付等。并且拥有完整的
下载
立即学习 “PHP免费学习笔记(深入) ”;
图 2. 用户列表 在进入下一个阶段之前,还需要编写一个小函数,该函数将返回当前用户正在追随的用户。这样一来,用户就可以用这个列表来确定是否追随另一个用户。
回到 functions.php 文件,添加一个名为 following() 的函数,如清单 12 所示。将当前用户 ID 传递给该函数,就可以得到该用户正在追随的每个用户的 ID。
清单 12. following() 函数
现在可以在 users.php 上运行这个函数,检查某个用户 ID 是否在该数组中。如果在,则使用 unfollow 链接。如果不在,则使用默认的 follow 链接。清单 13 显示修改后的代码。
清单 13. 修改后的 users.php 文件,它将显示 follow 和 unfollow 链接
有了 show_users() 函数之后,接下来可以创建一个 users.php 文件,该文件将运行这个函数,并显示系统中所有用户的一个列表,对于每个用户,在用户名的旁边都有一个 follow 链接。
清单 11. 运行 show_users() 函数的 users.php 文件
为了访问这个用户列表,在 index.php 文件中表单的上方添加一个到 users.php 的链接:
现在有了一个易于使用的用户名列表,每个用户名旁有一个 follow 链接。
立即学习 “PHP免费学习笔记(深入) ”;
图 2. 用户列表 在进入下一个阶段之前,还需要编写一个小函数,该函数将返回当前用户正在追随的用户。这样一来,用户就可以用这个列表来确定是否追随另一个用户。
回到 functions.php 文件,添加一个名为 following() 的函数,如清单 12 所示。将当前用户 ID 传递给该函数,就可以得到该用户正在追随的每个用户的 ID。
清单 12. following() 函数
现在可以在 users.php 上运行这个函数,检查某个用户 ID 是否在该数组中。如果在,则使用 unfollow 链接。如果不在,则使用默认的 follow 链接。清单 13 显示修改后的代码。
清单 13. 修改后的 users.php 文件,它将显示 follow 和 unfollow 链接
接下来的步骤很简单:创建 follow 和 unfollow 链接使用的 action.php 文件。该文件接受两个 GET 参数:一个用于用户 ID,另一个用于 follow 或 unfollow。如清单 14 所示,这个文件和 add.php 文件一样简短。
清单 14. action.php 文件
有了 show_users() 函数之后,接下来可以创建一个 users.php 文件,该文件将运行这个函数,并显示系统中所有用户的一个列表,对于每个用户,在用户名的旁边都有一个 follow 链接。
清单 11. 运行 show_users() 函数的 users.php 文件
为了访问这个用户列表,在 index.php 文件中表单的上方添加一个到 users.php 的链接:
现在有了一个易于使用的用户名列表,每个用户名旁有一个 follow 链接。
立即学习 “PHP免费学习笔记(深入) ”;
图 2. 用户列表 在进入下一个阶段之前,还需要编写一个小函数,该函数将返回当前用户正在追随的用户。这样一来,用户就可以用这个列表来确定是否追随另一个用户。
回到 functions.php 文件,添加一个名为 following() 的函数,如清单 12 所示。将当前用户 ID 传递给该函数,就可以得到该用户正在追随的每个用户的 ID。
清单 12. following() 函数
现在可以在 users.php 上运行这个函数,检查某个用户 ID 是否在该数组中。如果在,则使用 unfollow 链接。如果不在,则使用默认的 follow 链接。清单 13 显示修改后的代码。
清单 13. 修改后的 users.php 文件,它将显示 follow 和 unfollow 链接
有了 show_users() 函数之后,接下来可以创建一个 users.php 文件,该文件将运行这个函数,并显示系统中所有用户的一个列表,对于每个用户,在用户名的旁边都有一个 follow 链接。
清单 11. 运行 show_users() 函数的 users.php 文件
为了访问这个用户列表,在 index.php 文件中表单的上方添加一个到 users.php 的链接:
现在有了一个易于使用的用户名列表,每个用户名旁有一个 follow 链接。
立即学习 “PHP免费学习笔记(深入) ”;
图 2. 用户列表 在进入下一个阶段之前,还需要编写一个小函数,该函数将返回当前用户正在追随的用户。这样一来,用户就可以用这个列表来确定是否追随另一个用户。
回到 functions.php 文件,添加一个名为 following() 的函数,如清单 12 所示。将当前用户 ID 传递给该函数,就可以得到该用户正在追随的每个用户的 ID。
清单 12. following() 函数
现在可以在 users.php 上运行这个函数,检查某个用户 ID 是否在该数组中。如果在,则使用 unfollow 链接。如果不在,则使用默认的 follow 链接。清单 13 显示修改后的代码。
清单 13. 修改后的 users.php 文件,它将显示 follow 和 unfollow 链接
接下来的步骤很简单:创建 follow 和 unfollow 链接使用的 action.php 文件。该文件接受两个 GET 参数:一个用于用户 ID,另一个用于 follow 或 unfollow。如清单 14 所示,这个文件和 add.php 文件一样简短。
清单 14. action.php 文件
可以看到,这里取决于之前选择的链接,采取两种不同的动作 — follow_user() 或 unfollow_user() 。然后,设置一条消息,并将用户重定向回 index.php 页面。用户回到 index.php 页面后,不仅可以看到自己的消息,还可以看到他们追随的用户最近添加的消息。或者,如果之前选择 unfollow 链接,那么那个用户的消息将从列表中消失。稍后需要在 index.php 中添加这点代码。现在,将 follow_user() 和 unfollow_user() 函数添加到 functions.php 中。
对于这两个函数要小心一点。不能只是因为用户单击了那个链接,就盲目地追随或放弃追随一个用户。首先,需要检查 following 表中是否存在这样的关系。如果存在,那么可以忽略请求(单击 follow 链接时),或者接受请求(单击 unfollow 链接时)。为简单起见,编写两种情况下都可以使用的一个 check_count() 函数,如下面的清单所示。
清单 15. check_count() 函数
接下来的步骤很容易:在主页上显示当前用户正在追随的其他用户的列表。虽然已经有了一个 show_users() 函数,但那个函数是显示所有 用户。可以通过增加一个非必需的参数,轻松地改变这个函数的用途。这个参数是一个用户 ID,可以用该参数将用户列表限制为该用户 ID 所追随的那些用户。
清单 16 中重新编写的代码所做的事情是检查传入的 $user_id 参数。如果该用户 ID 大于 0,则使用一个查询获取此 ID 追随的所有用户的 ID。使用 implode() 函数将获得的数组转换为一个以逗号分隔的列表。然后将这个字符串 — 大致为 and id in (1,2,3...n) — 插入到已有的 SQL 查询中,从而将用户列表限制为该用户正在追随的那些用户。
清单 16. 重新编写的代码,用于限制通过查询获得的用户列表
接下来,将清单 17 中的代码添加到主页中,用于显示所有那些被追随的用户。
清单 17. 修改 index.php 以显示被追随的用户
有了 show_users() 函数之后,接下来可以创建一个 users.php 文件,该文件将运行这个函数,并显示系统中所有用户的一个列表,对于每个用户,在用户名的旁边都有一个 follow 链接。
清单 11. 运行 show_users() 函数的 users.php 文件
为了访问这个用户列表,在 index.php 文件中表单的上方添加一个到 users.php 的链接:
现在有了一个易于使用的用户名列表,每个用户名旁有一个 follow 链接。
立即学习 “PHP免费学习笔记(深入) ”;
图 2. 用户列表 在进入下一个阶段之前,还需要编写一个小函数,该函数将返回当前用户正在追随的用户。这样一来,用户就可以用这个列表来确定是否追随另一个用户。
回到 functions.php 文件,添加一个名为 following() 的函数,如清单 12 所示。将当前用户 ID 传递给该函数,就可以得到该用户正在追随的每个用户的 ID。
清单 12. following() 函数
现在可以在 users.php 上运行这个函数,检查某个用户 ID 是否在该数组中。如果在,则使用 unfollow 链接。如果不在,则使用默认的 follow 链接。清单 13 显示修改后的代码。
清单 13. 修改后的 users.php 文件,它将显示 follow 和 unfollow 链接
有了 show_users() 函数之后,接下来可以创建一个 users.php 文件,该文件将运行这个函数,并显示系统中所有用户的一个列表,对于每个用户,在用户名的旁边都有一个 follow 链接。
清单 11. 运行 show_users() 函数的 users.php 文件
为了访问这个用户列表,在 index.php 文件中表单的上方添加一个到 users.php 的链接:
现在有了一个易于使用的用户名列表,每个用户名旁有一个 follow 链接。
立即学习 “PHP免费学习笔记(深入) ”;
图 2. 用户列表 在进入下一个阶段之前,还需要编写一个小函数,该函数将返回当前用户正在追随的用户。这样一来,用户就可以用这个列表来确定是否追随另一个用户。
回到 functions.php 文件,添加一个名为 following() 的函数,如清单 12 所示。将当前用户 ID 传递给该函数,就可以得到该用户正在追随的每个用户的 ID。
清单 12. following() 函数
现在可以在 users.php 上运行这个函数,检查某个用户 ID 是否在该数组中。如果在,则使用 unfollow 链接。如果不在,则使用默认的 follow 链接。清单 13 显示修改后的代码。
清单 13. 修改后的 users.php 文件,它将显示 follow 和 unfollow 链接
接下来的步骤很简单:创建 follow 和 unfollow 链接使用的 action.php 文件。该文件接受两个 GET 参数:一个用于用户 ID,另一个用于 follow 或 unfollow。如清单 14 所示,这个文件和 add.php 文件一样简短。
清单 14. action.php 文件
有了 show_users() 函数之后,接下来可以创建一个 users.php 文件,该文件将运行这个函数,并显示系统中所有用户的一个列表,对于每个用户,在用户名的旁边都有一个 follow 链接。
清单 11. 运行 show_users() 函数的 users.php 文件
为了访问这个用户列表,在 index.php 文件中表单的上方添加一个到 users.php 的链接:
现在有了一个易于使用的用户名列表,每个用户名旁有一个 follow 链接。
立即学习 “PHP免费学习笔记(深入) ”;
图 2. 用户列表 在进入下一个阶段之前,还需要编写一个小函数,该函数将返回当前用户正在追随的用户。这样一来,用户就可以用这个列表来确定是否追随另一个用户。
回到 functions.php 文件,添加一个名为 following() 的函数,如清单 12 所示。将当前用户 ID 传递给该函数,就可以得到该用户正在追随的每个用户的 ID。
清单 12. following() 函数
现在可以在 users.php 上运行这个函数,检查某个用户 ID 是否在该数组中。如果在,则使用 unfollow 链接。如果不在,则使用默认的 follow 链接。清单 13 显示修改后的代码。
清单 13. 修改后的 users.php 文件,它将显示 follow 和 unfollow 链接
有了 show_users() 函数之后,接下来可以创建一个 users.php 文件,该文件将运行这个函数,并显示系统中所有用户的一个列表,对于每个用户,在用户名的旁边都有一个 follow 链接。
清单 11. 运行 show_users() 函数的 users.php 文件
为了访问这个用户列表,在 index.php 文件中表单的上方添加一个到 users.php 的链接:
现在有了一个易于使用的用户名列表,每个用户名旁有一个 follow 链接。
立即学习 “PHP免费学习笔记(深入) ”;
图 2. 用户列表 在进入下一个阶段之前,还需要编写一个小函数,该函数将返回当前用户正在追随的用户。这样一来,用户就可以用这个列表来确定是否追随另一个用户。
回到 functions.php 文件,添加一个名为 following() 的函数,如清单 12 所示。将当前用户 ID 传递给该函数,就可以得到该用户正在追随的每个用户的 ID。
清单 12. following() 函数
现在可以在 users.php 上运行这个函数,检查某个用户 ID 是否在该数组中。如果在,则使用 unfollow 链接。如果不在,则使用默认的 follow 链接。清单 13 显示修改后的代码。
清单 13. 修改后的 users.php 文件,它将显示 follow 和 unfollow 链接
接下来的步骤很简单:创建 follow 和 unfollow 链接使用的 action.php 文件。该文件接受两个 GET 参数:一个用于用户 ID,另一个用于 follow 或 unfollow。如清单 14 所示,这个文件和 add.php 文件一样简短。
清单 14. action.php 文件
可以看到,这里取决于之前选择的链接,采取两种不同的动作 — follow_user() 或 unfollow_user() 。然后,设置一条消息,并将用户重定向回 index.php 页面。用户回到 index.php 页面后,不仅可以看到自己的消息,还可以看到他们追随的用户最近添加的消息。或者,如果之前选择 unfollow 链接,那么那个用户的消息将从列表中消失。稍后需要在 index.php 中添加这点代码。现在,将 follow_user() 和 unfollow_user() 函数添加到 functions.php 中。
对于这两个函数要小心一点。不能只是因为用户单击了那个链接,就盲目地追随或放弃追随一个用户。首先,需要检查 following 表中是否存在这样的关系。如果存在,那么可以忽略请求(单击 follow 链接时),或者接受请求(单击 unfollow 链接时)。为简单起见,编写两种情况下都可以使用的一个 check_count() 函数,如下面的清单所示。
清单 15. check_count() 函数
接下来的步骤很容易:在主页上显示当前用户正在追随的其他用户的列表。虽然已经有了一个 show_users() 函数,但那个函数是显示所有 用户。可以通过增加一个非必需的参数,轻松地改变这个函数的用途。这个参数是一个用户 ID,可以用该参数将用户列表限制为该用户 ID 所追随的那些用户。
清单 16 中重新编写的代码所做的事情是检查传入的 $user_id 参数。如果该用户 ID 大于 0,则使用一个查询获取此 ID 追随的所有用户的 ID。使用 implode() 函数将获得的数组转换为一个以逗号分隔的列表。然后将这个字符串 — 大致为 and id in (1,2,3...n) — 插入到已有的 SQL 查询中,从而将用户列表限制为该用户正在追随的那些用户。
清单 16. 重新编写的代码,用于限制通过查询获得的用户列表
接下来,将清单 17 中的代码添加到主页中,用于显示所有那些被追随的用户。
清单 17. 修改 index.php 以显示被追随的用户
SESSION["userid"]);
if (count($users)){
?>
foreach ($users as $key => $value){ echo "\n"; echo "".$key ." \n"; echo "".$value; if (in_array($key,$following)){ echo " unfollow "; }else{ echo " follow "; } echo " \n"; echo " \n"; } ?>
接下来的步骤很简单:创建 follow 和 unfollow 链接使用的 action.php 文件。该文件接受两个 GET 参数:一个用于用户 ID,另一个用于 follow 或 unfollow。如清单 14 所示,这个文件和 add.php 文件一样简短。
清单 14. action.php 文件
可以看到,这里取决于之前选择的链接,采取两种不同的动作 — follow_user() 或 unfollow_user() 。然后,设置一条消息,并将用户重定向回 index.php 页面。用户回到 index.php 页面后,不仅可以看到自己的消息,还可以看到他们追随的用户最近添加的消息。或者,如果之前选择 unfollow 链接,那么那个用户的消息将从列表中消失。稍后需要在 index.php 中添加这点代码。现在,将 follow_user() 和 unfollow_user() 函数添加到 functions.php 中。
对于这两个函数要小心一点。不能只是因为用户单击了那个链接,就盲目地追随或放弃追随一个用户。首先,需要检查 following 表中是否存在这样的关系。如果存在,那么可以忽略请求(单击 follow 链接时),或者接受请求(单击 unfollow 链接时)。为简单起见,编写两种情况下都可以使用的一个 check_count() 函数,如下面的清单所示。
清单 15. check_count() 函数
接下来的步骤很容易:在主页上显示当前用户正在追随的其他用户的列表。虽然已经有了一个 show_users() 函数,但那个函数是显示所有 用户。可以通过增加一个非必需的参数,轻松地改变这个函数的用途。这个参数是一个用户 ID,可以用该参数将用户列表限制为该用户 ID 所追随的那些用户。
清单 16 中重新编写的代码所做的事情是检查传入的 $user_id 参数。如果该用户 ID 大于 0,则使用一个查询获取此 ID 追随的所有用户的 ID。使用 implode() 函数将获得的数组转换为一个以逗号分隔的列表。然后将这个字符串 — 大致为 and id in (1,2,3...n) — 插入到已有的 SQL 查询中,从而将用户列表限制为该用户正在追随的那些用户。
清单 16. 重新编写的代码,用于限制通过查询获得的用户列表
接下来,将清单 17 中的代码添加到主页中,用于显示所有那些被追随的用户。
清单 17. 修改 index.php 以显示被追随的用户
GET["id"];
$do =
追随其他用户
接下来可以将更多东西添加到 functions.php 文件中。这里需要一个 show_users() 函数,该函数可以返回系统中所有用户的一个列表。后面将使用这个函数填充一个用户列表。
清单 10. show_users() 函数
有了 show_users() 函数之后,接下来可以创建一个 users.php 文件,该文件将运行这个函数,并显示系统中所有用户的一个列表,对于每个用户,在用户名的旁边都有一个 follow 链接。
清单 11. 运行 show_users() 函数的 users.php 文件
为了访问这个用户列表,在 index.php 文件中表单的上方添加一个到 users.php 的链接:
现在有了一个易于使用的用户名列表,每个用户名旁有一个 follow 链接。
立即学习 “PHP免费学习笔记(深入) ”;
图 2. 用户列表 在进入下一个阶段之前,还需要编写一个小函数,该函数将返回当前用户正在追随的用户。这样一来,用户就可以用这个列表来确定是否追随另一个用户。
回到 functions.php 文件,添加一个名为 following() 的函数,如清单 12 所示。将当前用户 ID 传递给该函数,就可以得到该用户正在追随的每个用户的 ID。
清单 12. following() 函数
现在可以在 users.php 上运行这个函数,检查某个用户 ID 是否在该数组中。如果在,则使用 unfollow 链接。如果不在,则使用默认的 follow 链接。清单 13 显示修改后的代码。
清单 13. 修改后的 users.php 文件,它将显示 follow 和 unfollow 链接
$users = show_users(); $following = following(追随其他用户
接下来可以将更多东西添加到 functions.php 文件中。这里需要一个 show_users() 函数,该函数可以返回系统中所有用户的一个列表。后面将使用这个函数填充一个用户列表。
清单 10. show_users() 函数
function show_users(){ $users = array(); $sql = "select id, username from users where status="active" order by username"; $result = mysql_query($sql); while ($data = mysql_fetch_object($result)){ $users[$data->id] = $data->username; } return $users; } function show_users(){ $users = array(); $sql = "select id, username from users where status="active" order by username"; $result = mysql_query($sql); while ($data = mysql_fetch_object($result)){ $users[$data->id] = $data->username; } return $users; } session_start(); include_once("header.php"); include_once("functions.php"); ?> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Microblogging Application - Users List of Users $users = show_users(); if (count($users)){ ?> foreach ($users as $key => $value){ echo "\n"; echo "".$key ." \n"; echo "".$value ." follow \n"; echo " \n"; } ?>
}else{ ?>There are no users in the system!
} ?>see list of users
function following($userid){ $users = array(); $sql = "select distinct user_id from following where follower_id = "$userid""; $result = mysql_query($sql); while($data = mysql_fetch_object($result)){ array_push($users, $data->user_id); } return $users; } $users = show_users(); $following = following(追随其他用户
接下来可以将更多东西添加到 functions.php 文件中。这里需要一个 show_users() 函数,该函数可以返回系统中所有用户的一个列表。后面将使用这个函数填充一个用户列表。
清单 10. show_users() 函数
function show_users(){ $users = array(); $sql = "select id, username from users where status="active" order by username"; $result = mysql_query($sql); while ($data = mysql_fetch_object($result)){ $users[$data->id] = $data->username; } return $users; } session_start(); include_once("header.php"); include_once("functions.php"); ?> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Microblogging Application - Users List of Users $users = show_users(); if (count($users)){ ?> foreach ($users as $key => $value){ echo "\n"; echo "".$key ." \n"; echo "".$value ." follow \n"; echo " \n"; } ?>
}else{ ?>There are no users in the system!
} ?>see list of users
function following($userid){ $users = array(); $sql = "select distinct user_id from following where follower_id = "$userid""; $result = mysql_query($sql); while($data = mysql_fetch_object($result)){ array_push($users, $data->user_id); } return $users; } ___FCKpd___4 session_start(); include_once("header.php"); include_once("functions.php"); $id = 追随其他用户
接下来可以将更多东西添加到 functions.php 文件中。这里需要一个 show_users() 函数,该函数可以返回系统中所有用户的一个列表。后面将使用这个函数填充一个用户列表。
清单 10. show_users() 函数
function show_users(){ $users = array(); $sql = "select id, username from users where status="active" order by username"; $result = mysql_query($sql); while ($data = mysql_fetch_object($result)){ $users[$data->id] = $data->username; } return $users; } session_start(); include_once("header.php"); include_once("functions.php"); ?> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Microblogging Application - Users List of Users $users = show_users(); if (count($users)){ ?> foreach ($users as $key => $value){ echo "\n"; echo "".$key ." \n"; echo "".$value ." follow \n"; echo " \n"; } ?>
}else{ ?>There are no users in the system!
} ?>see list of users
function following($userid){ $users = array(); $sql = "select distinct user_id from following where follower_id = "$userid""; $result = mysql_query($sql); while($data = mysql_fetch_object($result)){ array_push($users, $data->user_id); } return $users; } $users = show_users(); $following = following(追随其他用户
接下来可以将更多东西添加到 functions.php 文件中。这里需要一个 show_users() 函数,该函数可以返回系统中所有用户的一个列表。后面将使用这个函数填充一个用户列表。
清单 10. show_users() 函数
function show_users(){ $users = array(); $sql = "select id, username from users where status="active" order by username"; $result = mysql_query($sql); while ($data = mysql_fetch_object($result)){ $users[$data->id] = $data->username; } return $users; } session_start(); include_once("header.php"); include_once("functions.php"); ?> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Microblogging Application - Users List of Users $users = show_users(); if (count($users)){ ?> foreach ($users as $key => $value){ echo "\n"; echo "".$key ." \n"; echo "".$value ." follow \n"; echo " \n"; } ?>
}else{ ?>There are no users in the system!
} ?>see list of users
function following($userid){ $users = array(); $sql = "select distinct user_id from following where follower_id = "$userid""; $result = mysql_query($sql); while($data = mysql_fetch_object($result)){ array_push($users, $data->user_id); } return $users; } ___FCKpd___4 ___FCKpd___5 function check_count($first, $second){ $sql = "select count(*) from following where user_id="$second" and follower_id="$first""; $result = mysql_query($sql); $row = mysql_fetch_row($result); return $row[0]; } function follow_user($me,$them){ $count = check_count($me,$them); if ($count == 0){ $sql = "insert into following (user_id, follower_id) values ($them,$me)"; $result = mysql_query($sql); } } function unfollow_user($me,$them){ $count = check_count($me,$them); if ($count != 0){ $sql = "delete from following where user_id="$them" and follower_id="$me" limit 1"; $result = mysql_query($sql); } } function show_users($user_id=0){ if ($user_id > 0){ $follow = array(); $fsql = "select user_id from following where follower_id="$user_id""; $fresult = mysql_query($fsql); while($f = mysql_fetch_object($fresult)){ array_push($follow, $f->user_id); } if (count($follow)){ $id_string = implode(",", $follow); $extra = " and id in ($id_string)"; }else{ return array(); } } $users = array(); $sql = "select id, username from users where status="active" $extra order by username"; $result = mysql_query($sql); while ($data = mysql_fetch_object($result)){ $users[$data->id] = $data->username; } return $users; } Users you"re following $users = show_users(追随其他用户
接下来可以将更多东西添加到 functions.php 文件中。这里需要一个 show_users() 函数,该函数可以返回系统中所有用户的一个列表。后面将使用这个函数填充一个用户列表。
清单 10. show_users() 函数
function show_users(){ $users = array(); $sql = "select id, username from users where status="active" order by username"; $result = mysql_query($sql); while ($data = mysql_fetch_object($result)){ $users[$data->id] = $data->username; } return $users; } session_start(); include_once("header.php"); include_once("functions.php"); ?> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Microblogging Application - Users List of Users $users = show_users(); if (count($users)){ ?> foreach ($users as $key => $value){ echo "\n"; echo "".$key ." \n"; echo "".$value ." follow \n"; echo " \n"; } ?>
}else{ ?>There are no users in the system!
} ?>see list of users
function following($userid){ $users = array(); $sql = "select distinct user_id from following where follower_id = "$userid""; $result = mysql_query($sql); while($data = mysql_fetch_object($result)){ array_push($users, $data->user_id); } return $users; } $users = show_users(); $following = following(追随其他用户
接下来可以将更多东西添加到 functions.php 文件中。这里需要一个 show_users() 函数,该函数可以返回系统中所有用户的一个列表。后面将使用这个函数填充一个用户列表。
清单 10. show_users() 函数
function show_users(){ $users = array(); $sql = "select id, username from users where status="active" order by username"; $result = mysql_query($sql); while ($data = mysql_fetch_object($result)){ $users[$data->id] = $data->username; } return $users; } session_start(); include_once("header.php"); include_once("functions.php"); ?> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Microblogging Application - Users List of Users $users = show_users(); if (count($users)){ ?> foreach ($users as $key => $value){ echo "\n"; echo "".$key ." \n"; echo "".$value ." follow \n"; echo " \n"; } ?>
}else{ ?>There are no users in the system!
} ?>see list of users
function following($userid){ $users = array(); $sql = "select distinct user_id from following where follower_id = "$userid""; $result = mysql_query($sql); while($data = mysql_fetch_object($result)){ array_push($users, $data->user_id); } return $users; } ___FCKpd___4 session_start(); include_once("header.php"); include_once("functions.php"); $id = 追随其他用户
接下来可以将更多东西添加到 functions.php 文件中。这里需要一个 show_users() 函数,该函数可以返回系统中所有用户的一个列表。后面将使用这个函数填充一个用户列表。
清单 10. show_users() 函数
function show_users(){ $users = array(); $sql = "select id, username from users where status="active" order by username"; $result = mysql_query($sql); while ($data = mysql_fetch_object($result)){ $users[$data->id] = $data->username; } return $users; } session_start(); include_once("header.php"); include_once("functions.php"); ?> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Microblogging Application - Users List of Users $users = show_users(); if (count($users)){ ?> foreach ($users as $key => $value){ echo "\n"; echo "".$key ." \n"; echo "".$value ." follow \n"; echo " \n"; } ?>
}else{ ?>There are no users in the system!
} ?>see list of users
function following($userid){ $users = array(); $sql = "select distinct user_id from following where follower_id = "$userid""; $result = mysql_query($sql); while($data = mysql_fetch_object($result)){ array_push($users, $data->user_id); } return $users; } $users = show_users(); $following = following(追随其他用户
接下来可以将更多东西添加到 functions.php 文件中。这里需要一个 show_users() 函数,该函数可以返回系统中所有用户的一个列表。后面将使用这个函数填充一个用户列表。
清单 10. show_users() 函数
function show_users(){ $users = array(); $sql = "select id, username from users where status="active" order by username"; $result = mysql_query($sql); while ($data = mysql_fetch_object($result)){ $users[$data->id] = $data->username; } return $users; } session_start(); include_once("header.php"); include_once("functions.php"); ?> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Microblogging Application - Users List of Users $users = show_users(); if (count($users)){ ?> foreach ($users as $key => $value){ echo "\n"; echo "".$key ." \n"; echo "".$value ." follow \n"; echo " \n"; } ?>
}else{ ?>There are no users in the system!
} ?>see list of users
function following($userid){ $users = array(); $sql = "select distinct user_id from following where follower_id = "$userid""; $result = mysql_query($sql); while($data = mysql_fetch_object($result)){ array_push($users, $data->user_id); } return $users; } ___FCKpd___4 ___FCKpd___5 function check_count($first, $second){ $sql = "select count(*) from following where user_id="$second" and follower_id="$first""; $result = mysql_query($sql); $row = mysql_fetch_row($result); return $row[0]; } function follow_user($me,$them){ $count = check_count($me,$them); if ($count == 0){ $sql = "insert into following (user_id, follower_id) values ($them,$me)"; $result = mysql_query($sql); } } function unfollow_user($me,$them){ $count = check_count($me,$them); if ($count != 0){ $sql = "delete from following where user_id="$them" and follower_id="$me" limit 1"; $result = mysql_query($sql); } } function show_users($user_id=0){ if ($user_id > 0){ $follow = array(); $fsql = "select user_id from following where follower_id="$user_id""; $fresult = mysql_query($fsql); while($f = mysql_fetch_object($fresult)){ array_push($follow, $f->user_id); } if (count($follow)){ $id_string = implode(",", $follow); $extra = " and id in ($id_string)"; }else{ return array(); } } $users = array(); $sql = "select id, username from users where status="active" $extra order by username"; $result = mysql_query($sql); while ($data = mysql_fetch_object($result)){ $users[$data->id] = $data->username; } return $users; } ___FCKpd___8 ___FCKpd___5 ___FCKpd___6 ___FCKpd___7 ___FCKpd___8 function show_users(){ $users = array(); $sql = "select id, username from users where status="active" order by username"; $result = mysql_query($sql); while ($data = mysql_fetch_object($result)){ $users[$data->id] = $data->username; } return $users; } session_start(); include_once("header.php"); include_once("functions.php"); ?> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Microblogging Application - Users List of Users $users = show_users(); if (count($users)){ ?> foreach ($users as $key => $value){ echo "\n"; echo "".$key ." \n"; echo "".$value ." follow \n"; echo " \n"; } ?>
}else{ ?>There are no users in the system!
} ?>see list of users
function following($userid){ $users = array(); $sql = "select distinct user_id from following where follower_id = "$userid""; $result = mysql_query($sql); while($data = mysql_fetch_object($result)){ array_push($users, $data->user_id); } return $users; }
PHP速学教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
下载
本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
文心一言
文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。
讯飞写作
基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿
即梦AI
一站式AI创作平台,免费AI图片和视频生成。
ChatGPT
最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。
java多线程方法汇总
本专题整合了java多线程面试题、实现函数、执行并发相关内容,阅读专题下面的文章了解更多详细内容。
1688阿里巴巴货源平台入口与批发采购指南
本专题整理了1688阿里巴巴批发进货平台的最新入口地址与在线采购指南,帮助用户快速找到官方网站入口,了解如何进行批发采购、货源选择以及厂家直销等功能,提升采购效率与平台使用体验。
C# 多线程与异步编程
本专题深入讲解 C# 中多线程与异步编程的核心概念与实战技巧,包括线程池管理、Task 类的使用、async/await 异步编程模式、并发控制与线程同步、死锁与竞态条件的解决方案。通过实际项目,帮助开发者掌握 如何在 C# 中构建高并发、低延迟的异步系统,提升应用性能和响应速度。
Python 微服务架构与 FastAPI 框架
本专题系统讲解 Python 微服务架构设计与 FastAPI 框架应用,涵盖 FastAPI 的快速开发、路由与依赖注入、数据模型验证、API 文档自动生成、OAuth2 与 JWT 身份验证、异步支持、部署与扩展等。通过实际案例,帮助学习者掌握 使用 FastAPI 构建高效、可扩展的微服务应用,提高服务响应速度与系统可维护性。
JavaScript 异步编程与事件驱动架构
本专题深入讲解 JavaScript 异步编程与事件驱动架构,涵盖 Promise、async/await、事件循环机制、回调函数、任务队列与微任务队列、以及如何设计高效的异步应用架构。通过多个实际示例,帮助开发者掌握 如何处理复杂异步操作,并利用事件驱动设计模式构建高效、响应式应用。
java中fail含义
本专题整合了java中fail的含义、作用相关内容,阅读专题下面的文章了解更多详细内容。
网站特效
/
网站源码
/
网站素材
/
前端模板