Small Twitter System source + notes, PHP
?
Let's do it today. The source code of the small Twitter system is a familiar piece of PHP.
For the next month's graduation plan.
?
Download the
Http://dl.vmall.com/c0nkwafdqz
?
Index
?
Microblogging applicationSee List of users
" . $_session [' message ']. ""; unset ($_session [' message ']);}? >
Headers
?
?
Sorry, could not connect to database.
Please contact your system's admin for more help\n ";" Exit ();} mysql_select_db ($DATABASE);? >
Users
Microblogging application-usersList of Users
$value) {//=> refers to getting the contents of an element within a cell within an array, echo "
\ n "; echo"
" . $key. " | \ n ";//Show Idecho"
unfollow follow";} echo " | \ n "; echo"
\ n ";}?" >
There is no users in the system!
?
?
0) {$extra = "limit $limit";} else {$extra = ";} $sql = "Select User_id,body, stamp from posts where user_id on ($user _string) Order BY stamp desc $extra"; echo $sql; $resul t = mysql_query ($sql), while ($data = Mysql_fetch_object ($result)) {$posts [] = array (' stamp ' = + $data->stam P, ' userid ' = $data->user_id, ' body ' and ' $data->body ');} return $posts;} /** * Show User * If user_id = 0, show all users directly * If User ID >0, display username changed user follow * @param unknown_type $user _id * @return multitype:| Multitype:null */function show_users ($user _id = 0) {if ($user _id > 0) {$follow = array (); $fsql = "Select user_id from Followingwhere follower_id= ' $user _id ' ";//select Follower$fresult = mysql_query ($fsql) from follow, while ($f = Mysql_fetch _object ($fresult)) {//Turn the result into a Array_push ($follow, $f->user_id);//Place the user_id field in F in Follow}if (count ($follow) {$id _string = implode (', ', $follow);//with "," as the delimiter to process this string, the stitching behind the Sql$extra = "and ID in ($id _string)";} else {return array ();}} $users= Array (); $sql = "SELECT ID, username from users where status= ' active ' $extra order by username";//select Follower ID from user table and Name$result = mysql_query ($sql), while ($data = Mysql_fetch_object ($result)) {$users [$data->id] = $data->u sername;//want to fill in user name}return $users;} /** * Search out user follow User ID * @param unknown_type $userid * @return Multitype: */function following ($userid) {$users = array ( $sql = "SELECT distinct user_id from followingwhere follower_id = ' $userid '", $result = mysql_query ($sql); while ($dat A = Mysql_fetch_object ($result)) {Array_push ($users, $data->user_id);} return $users;} function Check_count ($first, $second) {$sql = "SELECT count (*) from Followingwhere user_id= ' $second ' and follower_id= ' $fi Rst ' "; $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 (use r_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 followingwhe Re user_id= ' $them ' and follower_id= ' $me ' limit 1 '; $result = mysql_query ($sql);}}? >
Add
?
?