Jump to content

Database or TXT File


gaza165

Recommended Posts

There are so many more advantages of using a MySQL database over a txt file-storage system. First off it will be faster. Second off I'm sure you're going to want to limit chat displayed, that's much easier with MySQL. Google 'MySql vs text file' you'll find tons of reasons to use a database over a text file.

Link to comment
https://forums.phpfreaks.com/topic/163660-database-or-txt-file/#findComment-863514
Share on other sites

<?
include ('dbconnect.php');
include_once "init.inc.php";
require_once 'HTML/BBCodeParser.php';
$parser = new HTML_BBCodeParser(parse_ini_file('BBCodeParser.ini'));

$lastid = $_GET['lastid'];
$nick = $_GET['nick'];


$message = mysql_query("SELECT * FROM chat WHERE chat_id > '$lastid'") or die(mysql_error());

$maxid = mysql_query("SELECT MAX(chat_id) FROM chat");
$lastid = mysql_fetch_row($maxid);		
$lastid = $lastid[0];	

if(mysql_num_rows($message) == 0) { $norecords = "No Posts As Yet"; }


while ($row = mysql_fetch_array($message))
{


	$body = $row['message'];
	$body = str_replace('','<img src="img/smilies/485.png" width="15px" height="15px" class="icon">',$body);
	$body = str_replace('','<img src="img/smilies/486.png" width="15px" height="15px" class="icon">',$body);
	$body = str_replace('','<img src="img/smilies/363.png" width="15px" height="15px" class="icon">',$body);
	$body = str_replace(':S','<img src="img/smilies/286.gif" width="15px" height="15px" class="icon">',$body);
	$data = array('id'=>$row['chat_id'] , 'name'=>$row['nick'], 'message'=>$parser->qParse($body),'time'=>date("H:i:s",strtotime($row['timestamp'])));

} 

$json = '{"latest":"'.$lastid.'","noofposts":"'.$postrow[0].'", "response":[';
$json .= json_encode($data);
$json .= ']}';

echo $json;	



?>

 

 

function Get_Message() {				
$.getJSON("action/getmessages.php?lastid=" + id + "&nick=" + $("#name").val() + "&room_name=" + $('#room-select :selected').text(), function(json){					
id = json.latest;
$(".noofposts").html(json.noofposts);
$.each(json.response, function (i, item){
$("ul.shoutbox").append(
"<li><h4>" + item.time + "</h4><h2>" + item.name + ": </h2><p class='word-wrap'>" + item.message + "</p></li>" 				
);			
});		
});


var objDiv = document.getElementById("scroll");
objDiv.scrollTop = objDiv.scrollHeight;
}

 

Link to comment
https://forums.phpfreaks.com/topic/163660-database-or-txt-file/#findComment-863535
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.