php - Passing MySQL row count to javascript -


I am trying to find a way to use MySQL line count in JavaScript as a variable. After making a fool for a while, I always get 'undefined' as my variable.

I am very new to PHP and MySQL, but I know some way around Javascript.

{$ .get ("submissions .php", function (data) {console.log (data); return data;});}) ();

Submission Php

  $ sql = "Select from table"; Mysql_select_db ('database'); $ Result = mysql_query ($ sql, $ conn); $ Num_rows = mysql_num_rows ($ result); Repeat "$ num_rows";   

console.log is giving me the proper numerical value, however, 'the result' is undefined.

Any tips as to how to achieve this work?

Thank you.

You are having trouble scrolling which can be difficult to catch when you are using asynchronous programming Be new to all - who do all AJAX calls by default.

When you $ Get some , jQuery calls an http call on your server, which responds with something to an answer on something. Since your browser does not know how long the response will take, because it works, instead of blocking the rest of the site from functioning, the server lets the call wait in the background while answering. When your browser receives a response, it can execute the function that you gave it prematurely, with information from the server - a callback.

The code you want looks like this: function doThingsWithAjaxInfo (stuff) {// whatever you want to do with your server information) (Function () {$ .get ("submission.php", function (data) {doThingsWithAjaxInfo (info);});}) (); // The same thing but a bit cleaner, your callback on the returned data from the server will be automatically called // (function () {$ .get ("submission.php", doThingsWithAjaxInfo);});

Note that there is no return in the obtain function. Since the Ajax request ends almost immediately (but the callback does not slip until the server is responding), its return will not be useful to you (unless you want to use it, but I Do not recommend reaching unless you're more comfortable with regular callback driven asynchronous control flow.

The scope of handling in Javascript is difficult, especially when you have a Using asynchronous techniques like jacks, but it makes your code incredibly powerful, and it's worth the effort to get it right! Good luck!

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -