Home > Article > Backend Development > Chat program using line writing (Part 2)_PHP tutorial
lt1.php(as the current mainstream development language):
This program is the entrance to the entire system and contains two global parameters: chat_hh and uname, which record the current maximum speech number and speaker name respectively.
session_start();
session_register("chat_hh");
session_register("uname");
//Get the maximum value of the database No.
include("g_fun.php(as the current mainstream development language)");
f_connectdb();
$query = "select max(lt_id) as rmaxid from lt_t_content";
$res = MySQL(The best combination with PHP)_query($query, $dbh);
$row = MySQL(The best combination with PHP Best combination)_fetch_array($res);
$f_chat_hh = $row["rmaxid"];
if (empty($f_chat_hh)) { $f_chat_hh = 0; }
if ($ f_chat_hh > 12 ) {
$chat_hh=$f_chat_hh - 12;
} else
$chat_hh=$f_chat_hh;
$un_len=strlen($name);
$ uname=$name;
//Add online personnel information
$query = "select count(*) as rcount from lt_t_online where lt_username = ".$name."";
$res = MySQL(The best combination with PHP)_query($query, $dbh);
$row = MySQL(The best combination with PHP)_fetch_array($ res);
$lcount = $row["rcount"];
if ($lcount == 0) {
$query = "insert into lt_t_online(lt_username,lt_lasttime) values(";
$query .= "".$name.",now())";
$res = MySQL(The best combination with PHP)_query($query, $dbh);
}
$query = "update lt_t_online set lt_lasttime = now(),lt_state = 0 ";
$query .= " where lt_username = ".$name."";
$res = MySQL(The best combination with PHP)_query($query, $dbh);
?>