追随其他用户
接下来可以将更多东西添加到 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
任务管理器教程
本专题整合了任务管理器相关教程,阅读下面的文章了解更多详细操作。
AppleID格式
本专题整合了AppleID相关内容,阅读专题下面的文章了解更多详细教程。
添加脚注通用方法
本专题整合了添加脚注方法合集,阅读专题下面的文章了解更多内容。
重启电脑教程汇总
本专题整合了重启电脑操作教程,阅读下面的文章了解更多详细教程。
纸张尺寸汇总
本专题整合了纸张尺寸相关内容,阅读专题下面的文章了解更多内容。
Java Spring Boot 微服务实战
本专题深入讲解 Java Spring Boot 在微服务架构中的应用,内容涵盖服务注册与发现、REST API开发、配置中心、负载均衡、熔断与限流、日志与监控。通过实际项目案例(如电商订单系统),帮助开发者掌握 从单体应用迁移到高可用微服务系统的完整流程与实战能力。
网站特效
/
网站源码
/
网站素材
/
前端模板