Jump to content

blacknight

Members
  • Posts

    271
  • Joined

  • Last visited

Posts posted by blacknight

  1.  `id` int(11) NOT NULL AUTO_INCREMENT,
     `userID` int(11) NOT NULL,
      `userName` varchar(64) COLLATE utf8_bin NOT NULL,
      `level` varchar(64) COLLATE utf8_bin NOT NULL,
      `dateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
      `text` text COLLATE utf8_bin,
     PRIMARY KEY (`id`)");
    

    thats the table structure there is also a js part thats inserted to the header of the page for the use

    <script type=\'text/javascript\'>
    /* <![CDATA[ */
    var wr = {"userID":"'.$id.'","userName":"'.$name.'","level":"'.$level.'"
    };
    /* ]]> */
    </script>
    

    this script auto polls the db to the request file index.php?send=true but i would recommend using a script file then the index to do this but the link for the example this was based off is a much easier way to get started

    • Like 1
  2. im gona show you an example of a very basic chat app i designed

     

    the jquery

    $(document).ready(function(){
    	var IastID 		= 0;
    	var noActivity	= 0;
    	var nextRequest = 5000;
    	var update = updateChat();
    
    $('#inputField').keypress(function(e)
    	{
    		if (e.keyCode == 13 && !e.shiftKey)
    		{	
    			var text = $('#inputField').val();
    			
    			if(text != "")
    			{
    				// Assigning a temporary ID to the chat:
    				$.ajax({
    					type: "POST",
    					url: "index.php?send=true",
    					data: {  
    							'function'	: 'send',
    							userID		: wr.userID,
    							userName	: wr.userName,
    							level		: wr.level,
    							text		: text.replace(/</g,'<').replace(/>/g,'>')
    						 },
    					dataType: "json",
    					success: function(r){
    						$('#inputField').val('');
    						updateChat();
    					},
    				});
    
    				return false;
    			}
    		}
    	});
    	
    	function updateChat()
    	{
    		$.ajax({
    			type: "POST",
    			url: "index.php?hb=true",
    			data: {  
    					'function': 'heartbeat',
    					IastID: lastmsgid()
    				 },
    			dataType: "json",
    			success: function(r){
    				var h=[];
    				var g=[];
    
    				var z = r;
    				//g.push(channel);
    				for(var t=0;t<z.length;t++)
    				{
    					addChatLine(z[t]);
    				}
    				//alert(z.data.chats.length);
    				if(z.length){
    					noActivity = 0;
    					nextRequest = 4000;
    				}
    			},
    		});
    			
    		if(noActivity > 3){
    			nextRequest = 5000;
    		}
    		
    		if(noActivity > 10){
    			nextRequest = 10000;
    		}
    		
    		// 15 seconds
    		if(noActivity > 20){
    			nextRequest = 15000;
    		}
    		$('#activity').html('<p class="noChats">No chats yet '+noActivity+' hb time '+nextRequest+'</p>');
    		setTimeout(updateChat,nextRequest);
    
    	}
    	
    	function render(template,params){
    		
    		var arr = [];
    		switch(template){
    			case 'loginTopBar':
    				arr = [
    				'<span><img src="',params.gravatar,'" width="23" height="23" />',
    				'<span class="name">',params.name,
    				'</span><a href="" class="logoutButton rounded">Logout</a></span>'];
    			break;
    			case 'chatLine':
    				arr = ['<div class="chat" id="chat-',params.id,'" style="color: ',color[params.level],'!important;"><span class="author">',params.userName,
    					' : </span><span class="text">',params.text,'</span></div>'];
    
    			break;
    			
    			case 'user':
    				arr = [
    					'<div class="user" title="',params.name,'"><img src="',
    					params.gravatar,'" width="30" height="30" onload="this.style.visibility=\'visible\'" /></div>'
    				];
    			break;
    		}
    		// A single array join is faster than
    		// multiple concatenations
    		return arr.join('');
    	}
    	
    	function addChatLine(params){
    
    		// All times are displayed in the user's timezone
    		var d = new Date();
    		if(params.time) {	
    			// PHP returns the time in UTC (GMT). We use it to feed the date
    			// object and later output it in the user's timezone. JavaScript
    			// internally converts it for us.
    			d.setUTCHours(params.time.hours,params.time.minutes);
    		}
    		
    		params.time = (d.getHours() < 10 ? '0' : '' ) + d.getHours()+':'+
    					  (d.getMinutes() < 10 ? '0':'') + d.getMinutes();
    		
    		var markup = render('chatLine',params),
    			exists = $('#chat-'+params.id);
    
    		if(exists.length){
    			exists.remove();
    		}
    		
    		if(!IastID){
    			// If this is the first chat, remove the
    			// paragraph saying there aren't any:
    			$('.noChats').remove();
    		}
    		
    		// If this isn't a temporary chat:
    		if(params.id.toString().charAt(0) != 't'){
    			$('#chatroom').append(markup);
    		}
    		var sHeight = $('#chatroom')[0].scrollHeight;
    		$('#chatroom').scrollTop(sHeight);
    		
    	}
    	
    	function lastmsgid()
    	{
    		getID =  $('#chatroom').children('div').last().attr('id');//.replace('chat-','');
    		if (getID)
    		{
    			myarr = getID.split("-");
    			myvar = myarr[1];
    			IastID 		= myvar;
    		}
    		else
    		{
    			IastID 		= 0;
    		}
    	
    		return IastID;
    	}
    	
    });
    

    this is prity simple and has more features then you would want at the start thi s this uses timestamps avatars and usernames when chatting

     

    the html

    <div id="content" style="display: block;">
    
    	<div id="chatroom" class="chatrm">
    	</div>
    	
    	<div id="inputFieldContainer" class="inputbar">
    		<textarea id="inputField" class="mchatboxtextarea" title="Press SHIFT+ENTER to input a line break"></textarea>
    	</div>
    	
    </div>
    

    all the hard work is done by jquery so basic html the heartbeat checks the database for new messages the input sends the data to the processing page

     

    witch is like this...

    $function = $_POST['function'];
    
    	switch ($function)
    	{
    		case 'heartbeat':
    			$response = heartbeat();
    		break;
    		
    		case 'send':
    			$response = add_message($_POST);
    		break;
    	}
    	
    echo json_encode($response);
    
    function add_message($post)
    {
    	global $roster, $addon;
    	
    	$sql = "INSERT INTO `".$roster->db->table('messages',$addon['basename'])."` ".
    	"(`id`, `userID`, `userName`, `level`, `text`) VALUES ".
    	"(NULL, '".$post['userID']."', '".$post['userName']."', '".$post['level']."', '".$post['text']."');";
    	$result = $roster->db->query( $sql );
    	if ($result)
    	{
    		return array('status' => true);
    	}
    	else
    	{
    		return array('status' => false,'sql' => $sql);
    	}
    }
    function heartbeat()
    {	
    	global $roster, $addon;
    	
    	$sql = "Select * FROM `".$roster->db->table('messages',$addon['basename'])."`";
    	$result = $roster->db->query( $sql );
    	$mes = array();
    	while($d = $roster->db->fetch($result))
    	{
    		$mes[] =  $d;
    	}
    	
    	return $mes;
    }
    

    and thats all there is to my app really i hope this helps a lil

     

    here is the guide it was based off of

    http://css-tricks.com/jquery-php-chat/

    • Like 1
  3. i tryed your code i removed all the line brakes from the code and i have this

    $d = array("rowData"=> '<div class = "row" data-id = "'.$row['id'].'" ><div class = "row"><img src="data:image/jpeg;base64,'.base64_encode( $row['blob'] ).'"/></div><div class = "container"><div class = "name"><p>'.$row['name'] .'</p></div></div></div>');
    echo json_encode($d);
    

    and the output looks like 

     

     

      {"rowData":"<div class = \"row\" data-id = \"test2\" ><div class = \"row\"><img src=\"data:image\/jpeg;base64,ZXRzdDE=\"\/><\/div><div class = \"container\"><div class = \"name\"><p>test3<\/p><\/div><\/div><\/div>"}
  4. try using @mysql_free_result();

     

    some good tips

    - dont name all your querys the same number or letter them like $query1,$query2 ect. this would also apply to the $result

    - free the $result not the query this releases the resource from the database

     

    give these tips a try and it should start working

  5. so im working on this chat app for a sit im working on .. the main feature is a 3 room tabbed chat window each room displays the chat text and the users in the room but this is not my issue as its working as intended.

     

    my issue is we are adding group and user chat where a user can start a group room and chat with users they add and we want to use 1on1 user chats ... the question is should i use a separate hartbeat for each chat div or have 1 update them all?

  6. We are looking for some one to develop a jquery based chat script for our site some features needed are as fallows:

    • wordpress user integration
    • chat management ( mods,admins) kick ban report users
    • ability to create private chat rooms and invite multiple users to the room
    • users are able to ignore/block users
    • interactive user menu (left click on their name have a list for profile, add friend, invite to group chat, block, ignore and so on

    other options and so forth can be discussed when talking about said script

     

    we are looking for someone who is professional and has a very good knowledge of js to write this addon to our site please email me at

    ulminia (at) gmail (dot) com and we can arrange a skype meeting and discuss what you think you can do for us

     

    Thank you

  7. $ in php marks the calling of a var weather it be array or what not if the $ is used improperly it will error out

     

    $query .= "($" . "rel_student_uid, '$detention_date')";

     

    reads the $ as a var call with no var name

     

    $query .= "($rel_student_uid, '$detention_date')";

    reads the $rel_student_uid as a var for php to call

     

    any $ inside " " will be treated as a php var to avoid this if you are thing $ as just a character use mysql escape or enclose it in ' ' 

    this making any $ inside a ' ' reas as text unless code escaped with ' ' . $var . ' ' or for doubles " " . $var . " " i personally always code escape my var and use mysql escape

     

    i hope this helps

  8. ok im working on making a tooltip script using jquery...

     

    my tooltips are stored un this type of fashion..

     

    <script type="text/javascript">
    <!--//--><![CDATA
    var tiplib_1 = "Search items and recipes in the database";
    var tiplib_2 = "Roster Configuration Panel";
    var tiplib_3 = "Add a new guild and synchronize<br \/>the memberlist with Blizzard\'s Armory";
    var tiplib_4 = "Image screenshot database";
    //--><!]]>
    </script>
    

     

    this is located at the bottom of my page .. my question is how would i call this info so i can place it in a div container

     

    <div data-tip="tiplib_1" >This is link #4</div>

     

    $(document).ready(function(){
     simple_tooltip("[data-tip]","tooltip");
    });
    

    starts mt script

    function simple_tooltip(target_items, style){
    $(target_items).each(function(i){
    
     var Tip_name = $(this).attr("data-tip");
     //$("body").append("<div id='"+$(this).attr("data-tip")+"'>"+$($(this).attr("data-tip"))+"</div>");
     var myar = Tip_name.split('_');
     alert("id "+i+"- "+$(this).attr("data-tip")+"-"+myar[1]+"");
     $("<div id='"+Tip_name+"'>"+$(this).attr("data-tip")+"</div>").appendTo("body")
     $("#"+Tip_name).html(Tip_name);
     var my_tooltip = $("#"+Tip_name);
    

     

    Tip_name has the name of the var i wana call but for the life of me i cannoe make use get the value of the var and put it in the div any help?

  9. im gona make your life way easier.....

     

    basic check box array usage

     

    <input type="checkbox" name="delete[]" id="id#" value='id#' />

     

    id# being your cid number

     

    then you pass it using a form post

     

    heres the magic in php

     

    if (isset($_POST['delete']))
    {
    foreach ($_POST['delete'] as $c => $id)
    {
    	$d = "DELETE FROM `yourtablename` WHERE `cid` = '".$id."';";
    }
    }
    

     

    and you can now delete many boxes at the same time !

  10. ive been 3 days trying to figure out what the issue is with this menu

     

    you can see it here http://beta.wowroster.net/index.php?p=char-achievements&a=c:251

     

    the problem is if you click to expand "quests" then when you try and hover over "Exploration" you get some funky issue

     

    this is the css

    #rp_menu ul{margin:0;display:block;padding:0 0 0 10px;background:url(images/achv_lnav_bg.jpg) repeat-y;list-style-type:none;list-style-position:outside;width:165px; float:left;
    position:relative;line-height:22px;}
    
    #rp_menu ul li { display:block;color:#e7d6b8; margin:1px 5px 1px 5px;text-indent:5px;width:158px;}
    #rp_menu ul li.selected { background:url(images/achv_lnav_sel.png);text-indent:5px;width:158px;color:#C79C6E;}
    #rp_menu ul li.selected a { color:#C79C6E;}
    #rp_menu ul li:hover { color:white; background:url(images/achv_cat_hover.png) right repeat-y;text-indent:5px;width:158px; height: 22px;}
    #rp_menu ul li a { background:none;zoom:1; }
    #rp_menu ul li ul{display:none; background:url(images/achv_sel_sub_bg.png) bottom left no-repeat;width:152px;padding:4px 0px 6px 6px; margin:0 0 10px 0;}
    #rp_menu ul li ul li { display:block;color:#ABD473; margin:1px 5px 1px 5px; width:144px;text-indent:3px;}
    #rp_menu ul li ul li a{ color:#ABD473;}
    #rp_menu ul li ul li.selected2 { background:url(images/achv_lnav_sel.png);text-indent:5px;width:148px;color:#ABD473;}
    #rp_menu ul li ul li.selected2 a{ color:#ABD473;}
    #rp_menu ul li ul li:hover {background:url(images/achv_sub_hover.png)repeat-y; color:#AA5303;height: 22px;width:148px;}
    

     

    and thsi is the jquery code

    $(document).ready(function () {
    $('#menu li').children('ul').slideUp('fast');
    $('#amain > div#s81').show();
    var parent;
    $('#menu li').click(function(e) {
    	if ($(this).parents('li').size() > 0 ) 
    	{
    		//Has parent LI, so this is a child comment
    		$(this).siblings().removeClass("selected2"); //Remove any "active" class
    		$(this).addClass("selected2"); //Add "active" class to selected tab
    		$('div#amain > div').hide();
    		$("#amain > div#"+this.id).show();
    		parent = true;
    		return true;
    	}
    	else
    	{
    		if (!parent)
    		{
    			//Has no parent LI, top level comment
    			$('div#amain > div').hide();
    			$("li.menu_head").removeClass(" selected"); //Remove any "active" class
    			$(this).addClass(" selected");
    			$('#menu li').children('ul').slideUp('fast');
    			$("#amain > div#"+this.id).show();
    			$('li.menu_head#'+this.id+' > ul#sub').slideDown('400').show();
    		}
    		parent=false;
    	}
    });
    
    
    
    });
    

     

    any one have any ideas?

×
×
  • 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.