By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

HELP! Urgent. Using JS to retrieve data from DB = mission impossible?

P: n/a
We are trying to develop an Engineering application using PHP,
Javascript with Informix as the back-end.

Is it possible to retrieve data using Javascript but by accessing the
Database. Say somebody enters part_no, than using Javascript is it
possible to connect to the part master and retrieve the division and
desc information?

I am not allowed to use the PHP because this will require the user to
insert the part number on the first page (user input page) and then
retrieve the information using PHP and display the info on the second
page (processing page).

I will need this to be done on the same page. That means the info will
need to be retrieved instantly (on the fly).

I think of building a javascript array for the part master table using
PHP but finally decided not to as the table is a huge table (contains
more than 1000000 records).

Thanks in advance for your kindness help.

Mar 2 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
gg****@gmail.com wrote:
We are trying to develop an Engineering application using PHP,
Javascript with Informix as the back-end.

Is it possible to retrieve data using Javascript but by accessing the
Database. Say somebody enters part_no, than using Javascript is it
possible to connect to the part master and retrieve the division and
desc information?

Google for AJAX.

--
Ian Collins.
Mar 2 '06 #2

P: n/a
Hi, Ian. Thanks for suggestion. Can you please recommend to me any good
tutorial about AJAX?

Mar 2 '06 #3

P: n/a

gg****@gmail.com wrote:
We are trying to develop an Engineering application using PHP,
Javascript with Informix as the back-end.

Is it possible to retrieve data using Javascript but by accessing the
Database. Say somebody enters part_no, than using Javascript is it
possible to connect to the part master and retrieve the division and
desc information?
In my amateur opinion, yes. For instance, using the HTTPRequest object
(one of the methods used in AJAX).
I am not allowed to use the PHP because this will require the user to insert the part number on the first page (user input page) and then
retrieve the information using PHP and display the info on the second
page (processing page).
You may still need to use PHP or some other intermediary, unless you
are prepared to open your database to remote access (a security issue).
But this does not necessarily involve a change of page.

Effectively the HTTPRequest object will make a request from your client
web page to a PHP web page, which in turn will connect to the database,
extract data, and send this back to the HTTPRequest object. JavaScript
can then collect the information from the HTTPRequest object, and
dynamically update the same page.
I will need this to be done on the same page. That means the info will
need to be retrieved instantly (on the fly).
See above.
I think of building a javascript array for the part master table using
PHP but finally decided not to as the table is a huge table (contains
more than 1000000 records).


A new book on AJAX, is "Professional Ajax" - see
<URL:www.nczonline.net>

Regards

Julian Turner

Mar 2 '06 #4

P: n/a
Julian Turner wrote:
gg****@gmail.com wrote:
We are trying to develop an Engineering application using PHP,
Javascript with Informix as the back-end.

Is it possible to retrieve data using Javascript but by accessing the
Database. Say somebody enters part_no, than using Javascript is it
possible to connect to the part master and retrieve the division and
desc information?


In my amateur opinion, yes. For instance, using the HTTPRequest object
(one of the methods used in AJAX).
> I am not allowed to use the PHP because this will require the user

to
insert the part number on the first page (user input page) and then
retrieve the information using PHP and display the info on the second
page (processing page).


You may still need to use PHP or some other intermediary, unless you
are prepared to open your database to remote access (a security issue).
But this does not necessarily involve a change of page.

Effectively the HTTPRequest object will make a request from your client
web page to a PHP web page, which in turn will connect to the database,
extract data, and send this back to the HTTPRequest object. JavaScript
can then collect the information from the HTTPRequest object, and
dynamically update the same page.
I will need this to be done on the same page. That means the info will
need to be retrieved instantly (on the fly).


See above.
I think of building a javascript array for the part master table using
PHP but finally decided not to as the table is a huge table (contains
more than 1000000 records).


A new book on AJAX, is "Professional Ajax" - see
<URL:www.nczonline.net>

Regards

Julian Turner


AJAX is not the only method. It is also possible to use a script like
this, that accomplishes the same thing.

function GetPartNum(part_num) {
var jsel = document.createElement('SCRIPT');
jsel.type = 'text/javascript';
jsel.src = "somepage.php?part_num="+part_num;
document.body.appendChild (jsel);
}

function GotNewData(desc,division) {

alert("Desc: "+desc+"Division: "+division);

}

And the php file can look like this:

<?

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

$p = $_GET{'part_num'};#may want to do something to avoid injection...

#db connect
#db select database
#run query
#store escaped results in $desc & $div
#output results as a javascript function
echo "GotNewData(\"".$desc."\",\"".$div."\");";

?>

Now when this is appended, the function is run with the desired
partnumber. This is more compatible then the XMLHttpRequest Object.

There is no speed difference either, they both load as fast as the
server generates the file and how large the content is. Example of both
methods on a timer: http://www.endeavorpub.com/d/stress.php

- JS
http://www.endeavorpub.com/

Mar 2 '06 #5

P: n/a
Thank you very much to Ian, Julian and JS for your valuable advice. I
will need some time to digest the information and also the recommended
methods. I am quite relief now as this problem is actually solvable and
is not a "mission impossible". Lastly, thanks again and take care.

Mar 5 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.