Help With a PHP Chatroom Script Needed
Posted: Thu Jul 06, 2006 11:48 am
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am making a chatroom designed for the meetings of the organization LLAMA (don't ask). First of all, I have tried and tried to understand Java chatroom tutorials. I cannot. I had an idea to make a PHP chatroom. So far I have succeeded, except that in the [b]check()[/b] function, whenever it tries to run, the screen turns white and the title turns into the web address, so I believe it's not giving the browser any HTML information when the function tries to run. Below is the goal of the code, followed by the full web page code, with the bad function colored red.
This code creates an interface for a meeting, in which members of the organization over a certain rank in the meeting are allowed. The interface delays the meeting by ten minutes, to assure that everyone has a chance to sign in. All members over a certain rank are expected to sign in. Funnily, the code that enables the user to speak has not been created yet. Every person should vote either "yes" or "no" on the topic.Code: Select all
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?
$link = mysql_connect("mysql","bmroute","suscom");
mysql_select_db("llama",$link) or die("Unable to select database. Please send as much hate mail as you can to brandonllama for making this stupid non-llama-tastic bug.");
if ($username != "brandonllama") {
mysql_query("UPDATE meeting SET value = CONCAT(value,'<br>$username') WHERE type = 'signedin'");
}
$result = mysql_query("SELECT value FROM meeting WHERE type = 'between'");
$between = mysql_fetch_row($result);
$between = $between[0];
if ($between == "council") {$rank = 4;}
if ($between == "higher") {$rank = 14;}
if ($between == "high") {$rank = 19;}
$result = mysql_query("SELECT username FROM members WHERE rank > $rank AND username != 'Peterllama' AND username != 'brandontest'");
$numrows = mysql_num_rows($result);
$expecting = "";
$expectingarr = array();
for ($i = 0;$i < $numrows;$i++) {
if ($i == 0) {
$expecting .= mysql_result($result,$i);
}
if ($i != 0) {
$expecting .= "<br>" . mysql_result($result,$i);
}
$expectingarr[$i] = mysql_result($result,$i);
}
$result = mysql_query("SELECT value FROM meeting WHERE type = 'signedin'");
$signedin = mysql_fetch_row($result);
$signedin = $signedin[0];
$result = mysql_query("SELECT value FROM meeting WHERE type = 'start'");
$start = mysql_fetch_row($result);
$start = $start[0];
$result = mysql_query("SELECT value FROM meeting WHERE type = 'topic'");
$topic = mysql_fetch_row($result);
$topic = $topic[0];
$result = mysql_query("SELECT value FROM meeting WHERE type = 'votes'");
$votes = mysql_fetch_row($result);
$votes = $votes[0];
$result = mysql_query("SELECT value FROM meeting WHERE type = 'transcript'");
$transcript = mysql_fetch_row($result);
$transcript = $transcript[0];
$result = mysql_query("SELECT value FROM meeting WHERE type = 'voted'");
$voted = mysql_fetch_row($result);
$voted = $voted[0];
$notsignedinarr = array();
for ($i = 0;$i < count($expectingarr);$i++) {
if (substr_count($signedin,$expectingarr[$i]) == 0) {
$notsignedinarr[count($notsignedinarr)] = $expectingarr[$i];
}
}
for ($i = 0;$i < count($notsignedinarr);$i++) {
if ($i == 0) {
$notsignedin = $notsignedinarr[$i];
}
if ($i != 0) {
$notsignedin .= "<br>" . $notsignedinarr[$i];
}
}
$date = date("U");
function setVote($decision) {
if ($decision == 0) {$votestr = "n";}
if ($decision == 1) {$votestr = "y";}
mysql_query("UPDATE meeting SET value = CONCAT(value,'" . $votestr. "') WHERE type = 'votes'");
mysql_query("UPDATE meeting SET value = CONCAT(value,', " . $username . "') WHERE type = 'voted'");
}
function reWrite($where,$what) {
echo "<script language='javascript'>\ndocument.getElementById('" . $where . "').innerHTML = '" . $what . "';\n</script>";
}
function check() {
if ($start > $date) {
reWrite("voting","Meeting will start in:<br>" . ceil(($start - $date) / 60));
}
if ($start < $date) {
if (mysql_fetch_row(mysql_query("SELECT value FROM meeting WHERE type = 'votes'"))[0] != $votes) {
$votes = mysql_fetch_row(mysql_query("SELECT value FROM meeting WHERE type = 'votes'"))[0];
$toReWrite = "Voted yes: " . substr_count($votes,"y") . "<br>Voted no: " . substr_count($votes,"n") . "<br>Not voted: " . ((count($expectingarr) + 1) - strlen($votes));
if (substr_count($voted,$username) != 0) {
$toReWrite .= "You have already voted.";
}
if (substr_count($voted,$username) == 0) {
$toReWrite .= "<button onClick='<?setVote(1)?>'>Vote Yes</button><button onClick='<?setVote(0)?>'>Vote No</button>";
}
reWrite("voting",$toReWrite);
}
}
if (mysql_fetch_row(mysql_query("SELECT value FROM meeting WHERE type = 'transcript'"))[0] != $transcript) {
$transcript = mysql_fetch_row(mysql_query("SELECT value FROM meeting WHERE type = 'transcript'"))[0];
reWrite("transcript",$transcript);
}
if (mysql_fetch_row(mysql_query("SELECT value FROM meeting WHERE type = 'signedin'"))[0] != $signedin)
$signedin = mysql_fetch_row(mysql_query("SELECT value FROM meeting WHERE type = 'signedin'"))[0];
$notsignedinarr = array();
for ($i = 0;$i < count($expectingarr);$i++) {
if (substr_count($signedin,$expectingarr[$i]) == 0) {
$notsignedinarr[count($notsignedinarr)] = $expectingarr[$i];
}
}
for ($i = 0;$i < count($notsignedinarr);$i++) {
if ($i == 0) {
$notsignedin = $notsignedinarr[$i];
}
if ($i != 0) {
$notsignedin .= "<br>" . $notsignedinarr[$i];
}
}
reWrite("signedin",$signedin);
reWrite("notsignedin",$notsignedin);
}
}
?>
<div style="top:2%;height:20%;"><h1><?=$topic?></h1></div>
<div id="signedin" style="position:absolute;left:2%;width:20%;">Signed In<p><?=$signedin?></div>
<div id="transcript" style="position:absolute;top:20%;left:20%;right:20%;bottom:20%;width:60%;height:60%;border-style:solid;border-width:1;overflow:auto;"><?=$transcript?></div>
<div id="notsignedin" style="position:absolute;right:0%;width:20%;">Not Signed In<p><?=$notsignedin?></div>
<div id="voting" style="position:absolute;bottom:2%;height:20%;"></div>
<script language="javascript">
function javaCheck() {
<?check();?>
var t=setTimeout("javaCheck()",500);
}
javaCheck();
</script>
</body>
</html>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]