Using jQuery to manipulate MySQL Database
|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Using jQuery to manipulate MySQL DatabaseHi everyone.
This is my first post. I was hoping to see if anyone has done much with jQuery to manipulate MySQL data. Here's the scenario: I am making a leaderboard that has race competitors, their times, and position (among other attributes). The data is being fed into the MySQL database and I want to display the data on a leaderboard with live updates and position changes. I figured jQuery would be a good way to get to animation and effects I want. Has anyone done anything similar to this or have any ideas which functions would be useful for this project? Thanks. -- You received this message because you are subscribed to the Google Groups "jQuery UI" group. To post to this group, send email to jquery-ui@.... To unsubscribe from this group, send email to jquery-ui+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-ui?hl=en. |
|
|
Re: Using jQuery to manipulate MySQL DatabaseHi,
I believe you are confusing MySQL queries with JQuery; while MySQL is server side, JQuery is client side. The client should never be aware of what's going on at the server side less than it sends a request through a URL, and receives some response from it. For security's sake, a thumb rule is to let the client know as little as possible about how data is treated and even stored in your application. A rough diagram would show the layers as such (from what the user sees to how data is stored): [UI] <--> [JQuery] <--> [DOM] <--> [WebBrowser] <--> *Internet* *Internet* <--> [WebServer] <--> [Server scripts] <--> [ScriptingEngine] <--> [Database] I would suggest that you take a look at some server frameworks, mainly made in PHP (I recommend Zend Framework), for your server side manipulations. They usually have everything set up for you to start developping your web site/application. On Nov 7, 1:30 pm, Josh <jola...@...> wrote: > Hi everyone. > > This is my first post. I was hoping to see if anyone has done much > with jQuery to manipulate MySQL data. Here's the scenario: I am making > a leaderboard that has race competitors, their times, and position > (among other attributes). The data is being fed into the MySQL > database and I want to display the data on a leaderboard with live > updates and position changes. I figured jQuery would be a good way to > get to animation and effects I want. Has anyone done anything similar > to this or have any ideas which functions would be useful for this > project? Thanks. -- You received this message because you are subscribed to the Google Groups "jQuery UI" group. To post to this group, send email to jquery-ui@.... To unsubscribe from this group, send email to jquery-ui+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-ui?hl=en. |
|
|
Re: Re: Using jQuery to manipulate MySQL DatabaseYanick is correct. Unless there's a script somewhere that let's a
javascript connect directly to port 3306 on your server (the mysql port) there's no way to let the web browser talk directly to the mysql server using javascript. And even if there were, you don't want to let the world have access to your mysql server. A lot of problems with that. However, you can use jQueries Ajax methods to communicate to your server and run php/perl/ruby/python/ or whatever your favorite server side script is to act as an intermediary between the client browser and the mysql server. What you would do is something like this. And this is pseudocode, so I can tell you right now it won't run, but it should be pretty close. Go through the jquery docs on ajax to get the right syntax. <html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript> function loaddata() { $("#mydata").load("/myscripts/mydatascript.php"); } </head> <body> <input type="button" name="mybutton" id="mybutton" onclick="loaddata()"></input> <br> <div id="mydata"></div> </body> </html> Now here's the php page: <?php $connection = mysql_connect("localhost", "user", "password"); mysql_select_db("mydatabase", $connection); $mydata = mysql_query("select * from mytable", $connection); while ($myrow = mysql_fetch_array($mydata)) { $name = $myrow["name"]; $email = $myrow["email"]; print "<p>Email $name at <a href=\"$email\">$email</a></p>\n"; } ?> So what happens is that that when the html page is opened in a browser, all you see is a button. When you click the button, the loaddata function is called. The loaddata function uses jquery's ajax load method and calls the php page. The php script on the server gets data from the mysql database and prints it out. Jquery accepts that printout and inserts it into the div with the id "mydata". You don't have to use php, any server side application will work. And of course you can get really fancy and pass data to the script with get and post commands. You could do two buttons: <input type="button" name="mybutton" id="mybutton" onclick="loaddata(a)" value="Names starting with A"></input> <input type="button" name="mybutton" id="mybutton" onclick="loaddata(a)" value="Names starting with B"></input> Then loaddata would become: function loaddata(letter) { $("#mydata").load("/myscripts/mydatascript.php?startswith=" + letter); } the php would add this line and change the query like this: $letter = $_GET["letter"]; "select * from names where name like '$letter%'" Make sense? On Sun, Nov 8, 2009 at 7:59 AM, Yanick <yanick.rochon@...> wrote: > Hi, > I believe you are confusing MySQL queries with JQuery; > > while MySQL is server side, JQuery is client side. The client should > never be aware of what's going on at the server side less than it > sends a request through a URL, and receives some response from it. > > For security's sake, a thumb rule is to let the client know as little > as possible about how data is treated and even stored in your > application. > > A rough diagram would show the layers as such (from what the user sees > to how data is stored): > > [UI] <--> [JQuery] <--> [DOM] <--> [WebBrowser] <--> *Internet* > > *Internet* <--> [WebServer] <--> [Server scripts] <--> > [ScriptingEngine] <--> [Database] > > > I would suggest that you take a look at some server frameworks, mainly > made in PHP (I recommend Zend Framework), for your server side > manipulations. They usually have everything set up for you to start > developping your web site/application. > > > > On Nov 7, 1:30 pm, Josh <jola...@...> wrote: >> Hi everyone. >> >> This is my first post. I was hoping to see if anyone has done much >> with jQuery to manipulate MySQL data. Here's the scenario: I am making >> a leaderboard that has race competitors, their times, and position >> (among other attributes). The data is being fed into the MySQL >> database and I want to display the data on a leaderboard with live >> updates and position changes. I figured jQuery would be a good way to >> get to animation and effects I want. Has anyone done anything similar >> to this or have any ideas which functions would be useful for this >> project? Thanks. > > -- > > You received this message because you are subscribed to the Google Groups "jQuery UI" group. > To post to this group, send email to jquery-ui@.... > To unsubscribe from this group, send email to jquery-ui+unsubscribe@.... > For more options, visit this group at http://groups.google.com/group/jquery-ui?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "jQuery UI" group. To post to this group, send email to jquery-ui@.... To unsubscribe from this group, send email to jquery-ui+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-ui?hl=en. |
|
|
Re: Using jQuery to manipulate MySQL DatabaseIt's not really a UI related answer but for the live updates, you
would be able to use .ajax(). Depending on the back-end architecture you could set up a page that gets all the updated data from the database and using .load() , you would be able to just retrieve that page or just one element (I.e a <OL> or <UL>) that displays the current standing order of competitors. Then using that info you can do any kind of animation your heart desires. On Nov 7, 11:30 am, Josh <jola...@...> wrote: > Hi everyone. > > This is my first post. I was hoping to see if anyone has done much > with jQuery to manipulate MySQL data. Here's the scenario: I am making > a leaderboard that has race competitors, their times, and position > (among other attributes). The data is being fed into the MySQL > database and I want to display the data on a leaderboard with live > updates and position changes. I figured jQuery would be a good way to > get to animation and effects I want. Has anyone done anything similar > to this or have any ideas which functions would be useful for this > project? Thanks. -- You received this message because you are subscribed to the Google Groups "jQuery UI" group. To post to this group, send email to jquery-ui@.... To unsubscribe from this group, send email to jquery-ui+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-ui?hl=en. |
|
|
Re: Using jQuery to manipulate MySQL DatabaseHi Josh,
You might also consider using jqGris, and jQuery plugin. It creates a grid interface that can be customized with jQuery UI. In order to make it work, as several people have mentioned, you need some code on the server to deliver the data. With jqGrid, you can set that up pretty simply, then use timeout to have it reload data every so often. You can also have it page the data, ie. If you have screen room to display 20 rows, but you have 30 people on the leader board, you might display page one, then page two, then back to page one. Should be pretty simple to set up the javascript, and then the code on the server. HTH Sloan -- You received this message because you are subscribed to the Google Groups "jQuery UI" group. To post to this group, send email to jquery-ui@.... To unsubscribe from this group, send email to jquery-ui+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-ui?hl=en. |
| Free embeddable forum powered by Nabble | Forum Help |