Help on how to make an element that pops up when something in the Db changes?

Forum
Last Post
Threads / Messages

Infernette

CODE CODE CODE CODE CODE
Member
Joined
Jan 29, 2013
Messages
164
Points
0
Location
Where I live? I live home.
Mysidian Dollar
15,625
Okay I want to make something that when something the the DB changes (ex. A value like 'tricks' changes by someone tricks that person) a little icon pops up on the current page when it occurs, without refreshing. I was wondering if anyone had any pointer on how to get something like that started.

I just need a few tips in the right direction, you don't need to write up a code. I was wondering if with the mysidia base this would be possible as well, or if the base is not made to handle something this. I was just thinking of making a little game on my site so if it isn't possible it doesn't matter.


Thank you for any and all help, and I hope you have a good holiday. :wiii:

(I need to learn more stuff in coding ^^)
 
I didn't quite get it, like changing a value and something in the page changing automatically without refreshing? That I think only works with javascript I think, by calling update functions

What type of game is it? Thre might be some examples online in javascript for simple games
 
It's more of someone can push a button on your profile and it causes a value to change in the db, which changes your end without you refeshing. I was hoping to use it for a battle-esq system(person clicks attack, updates your end and shows you lost hp). I know javascript would be useful for sure, not so sure if it'll work with the mysidia page setup.
 
I see, I think that really requires javascript and maybe ajax, no idea how that can be easily achieved with just php in mysidia sorry x.x
 
jQuery and javascript seem to be working well with mysidia's script. Sorry to bump, just wanted to tell you! Didn't try ajax yet, which you would need to be able to communicate with the php which communicates with the database

If you put the script tags (includes or the functions themselves) in the header.tpl of the theme you are using they work properly ^^

try it:

in header.tpl (remove comments):

Code:
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> /* include jquery without downloading it */

<script>
function alertme(){ /*simple JS function that makes a popup */
	alert('omg');
}

$(document).ready(function(){ /* simple jQuery function that makes a popup when you click the menu (anywhere in the menu) */
       $('div #menu').click(function(){
                   alert('OMGGG');
        });
});
</script>

/////////REST OF CODE HERE////////////
</head>

template.tpl (to test first javascript alert):
Code:
///CODE BEFORE HERE///
<body onload="alertme()">
///REST OF CODE HERE///



And this makes it work in php pages (so the different elements/tags will work differently depending on the page)
inside the index() function
Code:
	    echo '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>';
	    echo "<script>	
	    	$(document).ready(function(){
		$('h1').click(function(){ /*send an alert when the title is clicked */
			alert('OMG2');
			});
	});</script>";

JS and jQuery work on the HTML basically, makes it hard to use it on mysidia's pages (at least I haven't found a new way to create new ids and classes? I still don't quite get how it works)
 
Last edited:
Question, what exactly does that example you posted do XD

Whatever it does, it definitely seems to be what I'm looking for- and I'm quite glad that it can be incorported with the site!
 
They all create popups depending on the situation xD JS and jQuery work with HTML. For example jQuery can be used to interact with HTML's tags. In the php example, if you use it say in the my adopts php page, it will activate an popup with the message "OMG2" as soon as you click on the page's title ( $('h1').click(function(){***code***}) <- when a h1 HTML element is clicked it creates a new function and does whatever the function should do).
There are many other functions besides click (when mouse hovers, when form's input field is selected, when submit button is clicked, etc).
The other JS function works whenever it is called. It can be called normally or on certain events (<body onload="alertme()"> when the body loads, calls the function).

That way you can check when someone clicks a button and it will change something in the page automatically. You can add HTML elements and change them (even their CSS!). For example with this $('div').append('<div>NEW DIV</div>') it will add a new div to the page without refreshing after div (like so http://api.jquery.com/append ).

However, to check the DB you will need ajax as well x.x but you most likely can use it, since jQuery works
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,119
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top