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/