-2

Does anyone have any advice on how to run mysql queries using JQuery?

I am attempting to implement a system using jquery mobile with a mysql database as the backend. Are there any useful tutorials that I could follow to learn how to use ajax to call php functions that would contact a mysql database?

6
  • Look up some documentation on AJAX. This subject has been answered a bazillion times before on and off SO. Commented Feb 24, 2014 at 15:34
  • A google search returns page after page with tutorials and guides. First one I found Commented Feb 24, 2014 at 15:35
  • 1
    @lxndr: w3fools... don't link to them. their code is at best bad, and overall badly written and dangerous. Commented Feb 24, 2014 at 15:37
  • "Google it" responses bug me. Usually when I'm in this position, I'm asking because I don't know what to google. At least recommend a specific search. In this case, I googled "jquery mysql" and got a few promising hits. Here's a few: stackoverflow.com/questions/8598659/…, openenergymonitor.org/emon/node/107 Commented Feb 24, 2014 at 15:46
  • 1
    @gridDragon: The problem is that often, the first Google result when Googleing the title of the question is a relevant resource already. Programmers need to learn how to research instead of asking for the solution. Commented Feb 24, 2014 at 15:49

2 Answers 2

0

You won't run MySQL queries with JQuery directly. Set up a PHP file on your server that reads the needed information from $_REQUEST, $_POST, or $_GET (depends on how you want to implement it), then inserts that information into your query and handles the database call.

Once the database responds, you can send the information back to your jQuery app with

echo php_jsonencode($data); //Data is what ever value you got from the database.

That will send your database data back to jQuery as JSON so it's easier to parse.

The details on how you accomplish these steps are very dependent on the information your sending, and what you need to send back. So I can't answer more specifically without more details.

Sign up to request clarification or add additional context in comments.

Comments

0

If you want to call PHP functions from jQuery (JavaScript) itself, it is impossible as JavaScript is client side and PHP is server side. Still there are ways to communicate with your database using JavaScript. The most common way is using AJAX where you call a PHP file or another server side script with some code to communicate.

$("form").submit(function(event) {
  event.preventDefault();

  $.ajax({
    type:     "POST",
    url:      $(this).attr("action"),
    data:     $(this).find("input[name='needed']").val()
  });

  return false;
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.