Re: [PHP-DB] Read file
hi neil, this is indeed a very helpful piece of code and advice.. thank you so much! if this took you 30 minutes to write, it would have taken me a day to learn XML, and start writing! this code looks complicated for a young programmer like me ;p.. i'll need time to read up on XML and get back to you again if i have queries about the codes.. you really helped cut my learning curve in XML and at the same time solve my client-server problem.. may you be blessed just like how your codes have blessed me! :o) thanx lots, Hwee Hwee - Original Message - From: "Neil Smth" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Thursday, November 20, 2003 4:02 AM Subject: Re: [PHP-DB] Read file > It's usually easier to show with an example : This took about 30 minutes to > write : > > Here's an XML file - copy and paste, and save as hotels.xml : > > > > > 1 > Bangkok oriental > 50 High Street, Kowloon > +12 451 708 3282 > > > 2 > Hilton Marriott > 2042 Michael Wood Street > +44 238 9125467 > > > 3 > Swallow Royal > 91-97 Royal Fort Crescent > +01 1209 432 2345 > > > > At 10:21 19/11/2003 +, you wrote: > > >Hi Neil, > > > >thank you so much for your advice! i have not programmed XML before so it > >will take me a while to learn it.. your suggestion sounds really fantastic, > >expecially the part when i don't even have to ask the users to direct me to > >the file that i need.. > > > >my problem, simply put will be: > >1) user has to enter details in a form > >2) when user enters HotelCode in one of the fields in the form, > >3) javascript must pass the value to PHP to search for the HotelName, > >HotelAddress, HotelTel etc.. > > Forget about PHP if you are doing this client side, you only need it to > process the updated records : > > >5) javascript place those values in the respective fields > >6) user continues to complete the form > > Here is a processing page which will populate the form using the XML data : > Save this in the same directory you placed the hotels.xml file; It will > work in IE5 as is : > > > > Demo Hotel Loader > > > > > <!-- > oxmlDocument = new ActiveXObject("MSXML2.DOMDocument"); > oxmlDocument.load("hotels.xml"); > > function populatelist() { > var hotels=oxmlDocument.selectNodes("/hotels/hotel"); > if (hotels != null) { > d=document.forms["hotelupdate"].list; > d.length=0; > d[0]=new Option('--Please Select--','',true); > for (i=0;i<hotels.length;i++) { > d.length++; > d[i+1]=new Option(); > d[i+1].value=hotels[i].selectSingleNode("id").text; > d[i+1].text=hotels[i].selectSingleNode("name").text; > } > } > } > > function populatevalues() { > d=document.forms["hotelupdate"]; > // Get hotel ID # > v=d.list[d.list.selectedIndex].value; > // Use this to read the hotel/phone node having this hotel ID > field=oxmlDocument.selectSingleNode("/hotels/hotel[id='"+v+"']/phone"); > // Set form's phone field to the text of this node > d.phone.value=field.text; > // Now to read the hotel/address node having this hotel ID > field=oxmlDocument.selectSingleNode("/hotels/hotel[id='"+v+"']/address"); > // Set form's address field to the text of this node > d.address.value=field.text; > } > //--> > > > method="http://www.my-server.com/myurl.php"; onsubmit="alert('This would > send these values to your website');return false;"> > Phone : > > > wrap="virtual"> > > > > > > > > You then need to write some PHP to accept the new record (you might give > the ID number from your database as the primary key). Writing out XML from > PHP works exactly the same as writing out HTML. You just fill in the blanks > with your data by running a query and printing out the values between the > tags, in a loop. > > Hope that helps - study the code and see if you can understand how it works. > Cheers - Neil. > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP-DB] Read file
OK Error in my last post, the mail reader munged the HTML so if you need as source use the XML data below and hopefully the text below will appear as html code ;-) Cheers - Neil <html> <head> <title>Demo Hotel Loader</title> </head> <body onload="populatelist()"> <script language="javascript1.2"> <!-- oxmlDocument = new ActiveXObject("MSXML2.DOMDocument"); oxmlDocument.load("hotels.xml"); function populatelist() { var hotels=oxmlDocument.selectNodes("/hotels/hotel"); if (hotels != null) { d=document.forms["hotelupdate"].list; d.length=0; d[0]=new Option('--Please Select--','',true); for (i=0;i function populatevalues() { d=document.forms["hotelupdate"]; // Get hotel ID # v=d.list[d.list.selectedIndex].value; // Use this to read the hotel/phone node having this hotel ID field=oxmlDocument.selectSingleNode("/hotels/hotel[id='"+v+"']/phone"); // Set form's phone field to the text of this node d.phone.value=field.text; // Now to read the hotel/address node having this hotel ID field=oxmlDocument.selectSingleNode("/hotels/hotel[id='"+v+"']/address"); // Set form's address field to the text of this node d.address.value=field.text; } //--> </script> <form name="hotelupdate" id="hotelupdate" action="post" method="http://www.my-server.com/myurl.php"; onsubmit="alert('This would send these values to your website');return false;"> <select name="list" id="list" onchange="populatevalues()"></select> Phone : <input type="text" name="phone" id="phone" size="15" maxlength="24" /> <br /> <textarea name="address" id="address" rows="3" cols="40" wrap="virtual"></textarea> <br /> <input type="submit" name="submit" id="submit" value="Send !" /> </form> </body> </html> At 13:25 20/11/2003 +, you wrote: Date: Wed, 19 Nov 2003 20:02:43 + To: [EMAIL PROTECTED] From: Neil Smth <[EMAIL PROTECTED]> Cc: [EMAIL PROTECTED] Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DB] Read file It's usually easier to show with an example : This took about 30 minutes to write : Here's an XML file - copy and paste, and save as hotels.xml : 1 Bangkok oriental 50 High Street, Kowloon +12 451 708 3282 2 Hilton Marriott 2042 Michael Wood Street +44 238 9125467 3 Swallow Royal 91-97 Royal Fort Crescent +01 1209 432 2345 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Read file
It's usually easier to show with an example : This took about 30 minutes to write : Here's an XML file - copy and paste, and save as hotels.xml : 1 Bangkok oriental 50 High Street, Kowloon +12 451 708 3282 2 Hilton Marriott 2042 Michael Wood Street +44 238 9125467 3 Swallow Royal 91-97 Royal Fort Crescent +01 1209 432 2345 At 10:21 19/11/2003 +, you wrote: Hi Neil, thank you so much for your advice! i have not programmed XML before so it will take me a while to learn it.. your suggestion sounds really fantastic, expecially the part when i don't even have to ask the users to direct me to the file that i need.. my problem, simply put will be: 1) user has to enter details in a form 2) when user enters HotelCode in one of the fields in the form, 3) javascript must pass the value to PHP to search for the HotelName, HotelAddress, HotelTel etc.. Forget about PHP if you are doing this client side, you only need it to process the updated records : >5) javascript place those values in the respective fields 6) user continues to complete the form Here is a processing page which will populate the form using the XML data : Save this in the same directory you placed the hotels.xml file; It will work in IE5 as is : Demo Hotel Loader http://www.my-server.com/myurl.php"; onsubmit="alert('This would send these values to your website');return false;"> Phone : You then need to write some PHP to accept the new record (you might give the ID number from your database as the primary key). Writing out XML from PHP works exactly the same as writing out HTML. You just fill in the blanks with your data by running a query and printing out the values between the tags, in a loop. Hope that helps - study the code and see if you can understand how it works. Cheers - Neil. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP-DB] Read file
Hi Neil, thank you so much for your advice! i have not programmed XML before so it will take me a while to learn it.. your suggestion sounds really fantastic, expecially the part when i don't even have to ask the users to direct me to the file that i need.. my problem, simply put will be: 1) user has to enter details in a form 2) when user enters HotelCode in one of the fields in the form, 3) javascript must pass the value to PHP to search for the HotelName, HotelAddress, HotelTel etc.. 4) and then PHP pass the fetched variables back to javascript 5) javascript place those values in the respective fields 6) user continues to complete the form through many of the help from people on this list and on the web, i think maybe i can: 1) create a frame and write my PHP query statements in it 2) set a cookie when the user enters the HotelCode 3) reload the frame with the PHP code and get the variable with $_COOKIE 4) on the same frame, echo the fetched variables into javascript fields have not try this out yet.. but if anyone has any thoughts, would love to hear it! thanks much, hwee - Original Message - From: "Neil Smth" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Wednesday, November 19, 2003 6:28 AM Subject: Re: Re: [PHP-DB] Read file > You would benefit from using XML for these data structures. XSLT can be > used to quickly filter records stored on the clients computer locally. The > client can then make changes to desired records and upload the XML file > fragment to the server. The server then has a much lower load as it only > has to process the changed records. > > I would (and have) get the user to download a ZIP file containing the XML > file, a web page which processes it and some javascript support files. When > the ZIP is unpacked, the page can then load the XML file from the current > directory (containing the web page), you would not need to know anything > about the user's directory structure, and they would not have to browse for > the file when they use your application. > > Another optimisation might be to have the client browser start, and then > query a URL provided by you. The URL would offer a 'last-updated' date as > another XML file. Comparing this with a value which you store inside your > provided XML file would allow the browser to alert the user that a new file > was available, and to visit your website to download a new ZIP file. > > Both IE and Mozilla support loading and scripting of XML / XSL transformations > > In IE you might want to read up on the xmlhttp.load and xmlhttp.send > function to read remote XML files. (This will require MSXML2.6 or above) > > Hope that helps, I'm not really too sure what you are trying to do, even > with your description below - maybe a diagram would help us to understand > your problem ? > > Cheers - Neil > > At 15:00 18/11/2003 +, Ng Hwee Hwee > > >From: "Ng Hwee Hwee" <[EMAIL PROTECTED]> > >To: "Michael Scappa" <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> > >Date: Tue, 18 Nov 2003 10:27:26 +0800 > >MIME-Version: 1.0 > >Content-Type: text/plain; > > charset="iso-8859-1" > >Content-Transfer-Encoding: 7bit > >Subject: Re: [PHP-DB] Read file > > > >what about using cookies? > > > >my problem is this: i have about 10,000 hotels records and each of them has > >information about its location, its hotel code, its hotel tel, its country > >code etc... i would like to load this into the clients computer so that when > >they enter a hotel code, all the information will be reflected in the form > >using onChange()... if 50 employees were to query the database always for > >these 10,000 records, i'm afraid the server can't take the traffic and die.. > >so i was thinking of uploading a CSV file into my client's computer and then > >have my scripts find the file and read the file for Javascript to process... > >since the information in the file changes ususally only once a year, i don't > >have to worry that they will have back-dated information.. > > > >i'm desperate for enlightenment! thanx!! :o) > > > >blessings, > >hwee > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP-DB] Read file
You would benefit from using XML for these data structures. XSLT can be used to quickly filter records stored on the clients computer locally. The client can then make changes to desired records and upload the XML file fragment to the server. The server then has a much lower load as it only has to process the changed records. I would (and have) get the user to download a ZIP file containing the XML file, a web page which processes it and some javascript support files. When the ZIP is unpacked, the page can then load the XML file from the current directory (containing the web page), you would not need to know anything about the user's directory structure, and they would not have to browse for the file when they use your application. Another optimisation might be to have the client browser start, and then query a URL provided by you. The URL would offer a 'last-updated' date as another XML file. Comparing this with a value which you store inside your provided XML file would allow the browser to alert the user that a new file was available, and to visit your website to download a new ZIP file. Both IE and Mozilla support loading and scripting of XML / XSL transformations In IE you might want to read up on the xmlhttp.load and xmlhttp.send function to read remote XML files. (This will require MSXML2.6 or above) Hope that helps, I'm not really too sure what you are trying to do, even with your description below - maybe a diagram would help us to understand your problem ? Cheers - Neil At 15:00 18/11/2003 +, Ng Hwee Hwee From: "Ng Hwee Hwee" <[EMAIL PROTECTED]> To: "Michael Scappa" <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> Date: Tue, 18 Nov 2003 10:27:26 +0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DB] Read file what about using cookies? my problem is this: i have about 10,000 hotels records and each of them has information about its location, its hotel code, its hotel tel, its country code etc... i would like to load this into the clients computer so that when they enter a hotel code, all the information will be reflected in the form using onChange()... if 50 employees were to query the database always for these 10,000 records, i'm afraid the server can't take the traffic and die.. so i was thinking of uploading a CSV file into my client's computer and then have my scripts find the file and read the file for Javascript to process... since the information in the file changes ususally only once a year, i don't have to worry that they will have back-dated information.. i'm desperate for enlightenment! thanx!! :o) blessings, hwee -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Read file
I've seen it done with some creative javascript. (i.e. caching to a tmp dir and accessing the txt file onChange.) But you cannot (REPEAT CANNOT) execute php on a client machine unless you load php and a web server onto that client machine. PHP is still a server side script. And 10k cookies is out of the question. I imagine it would bring down your browser. You are correct to be concerned about people bringing down 10k records each time. I suggest you re-think your database strategy so that you bring down a smaller subset. If done right, you can use Javascript and a hidden window to fetch records from the database and return them to the currently running page without refreshing the page. (It can be done. It's ugly and it's a bugger to maintain, but it can be done.) Let me know how I may be of service, =C= * Cal Evans * http://www.eicc.com * We take care of your IT, * So you can take care of your business. * * I think inside the sphere. Ng Hwee Hwee wrote: what about using cookies? my problem is this: i have about 10,000 hotels records and each of them has information about its location, its hotel code, its hotel tel, its country code etc... i would like to load this into the clients computer so that when they enter a hotel code, all the information will be reflected in the form using onChange()... if 50 employees were to query the database always for these 10,000 records, i'm afraid the server can't take the traffic and die.. so i was thinking of uploading a CSV file into my client's computer and then have my scripts find the file and read the file for Javascript to process... since the information in the file changes ususally only once a year, i don't have to worry that they will have back-dated information.. i'm desperate for enlightenment! thanx!! :o) blessings, hwee - Original Message - From: "Michael Scappa" <[EMAIL PROTECTED]> To: "'Ng Hwee Hwee'" <[EMAIL PROTECTED]> Sent: Tuesday, November 18, 2003 10:01 AM Subject: RE: [PHP-DB] Read file If you are publishing it on the web, it has to get to the server eventually, so your answer is "no". There is really no way around it. If the file is often used, pump it into a DB and search it that way, it'll be much quicker. -Original Message- From: Ng Hwee Hwee [mailto:[EMAIL PROTECTED] Sent: Monday, November 17, 2003 8:58 PM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Read file the reason i don't want to read from the server is because i don't want to use up too much space and processing time on the server.. the file has 50,000 records of information.. is there another way other than uploading on the server side?? thanx! hwee - Original Message - From: "Jason Wong" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, November 18, 2003 9:54 AM Subject: Re: [PHP-DB] Read file On Tuesday 18 November 2003 09:29, Ng Hwee Hwee wrote: can anyone enlighten me on how i can use PHP to read the contents of a file from the client's machine?? for eg, the client has a CSV file in his MyDocuments directory, how can I read the contents and publish them on the web? You have to ask them to upload it to the server: manual > Handling file uploads -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Read file
Jason Wong wrote: > On Tuesday 18 November 2003 09:58, Ng Hwee Hwee wrote: > >>the reason i don't want to read from the server is because i don't want to >>use up too much space and processing time on the server.. the file has >>50,000 records of information.. >> >>is there another way other than uploading on the server side?? > > > Two options: > > 1) You can recompile PHP with the startrek module and use startrek_transport() > to instantly transfer anything (data, even physical objects) from anywhere to > anywhere else. > This requires lib-dilithium.so.6 and it's currently only in the devel branch. (So I wouldn't run it in a production environment.) Let me know how I may be of service, =C= * Cal Evans * http://www.eicc.com * We take care of your IT, * So you can take care of your business. * * I think inside the sphere. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Read file
what about using cookies? my problem is this: i have about 10,000 hotels records and each of them has information about its location, its hotel code, its hotel tel, its country code etc... i would like to load this into the clients computer so that when they enter a hotel code, all the information will be reflected in the form using onChange()... if 50 employees were to query the database always for these 10,000 records, i'm afraid the server can't take the traffic and die.. so i was thinking of uploading a CSV file into my client's computer and then have my scripts find the file and read the file for Javascript to process... since the information in the file changes ususally only once a year, i don't have to worry that they will have back-dated information.. i'm desperate for enlightenment! thanx!! :o) blessings, hwee - Original Message - From: "Michael Scappa" <[EMAIL PROTECTED]> To: "'Ng Hwee Hwee'" <[EMAIL PROTECTED]> Sent: Tuesday, November 18, 2003 10:01 AM Subject: RE: [PHP-DB] Read file > If you are publishing it on the web, it has to get to the server > eventually, so your answer is "no". There is really no way around it. If > the file is often used, pump it into a DB and search it that way, it'll > be much quicker. > > -Original Message- > From: Ng Hwee Hwee [mailto:[EMAIL PROTECTED] > Sent: Monday, November 17, 2003 8:58 PM > To: [EMAIL PROTECTED] > Subject: Re: [PHP-DB] Read file > > the reason i don't want to read from the server is because i don't want > to > use up too much space and processing time on the server.. the file has > 50,000 records of information.. > > is there another way other than uploading on the server side?? > > thanx! > hwee > > > ----- Original Message - > From: "Jason Wong" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Tuesday, November 18, 2003 9:54 AM > Subject: Re: [PHP-DB] Read file > > > > On Tuesday 18 November 2003 09:29, Ng Hwee Hwee wrote: > > > > > can anyone enlighten me on how i can use PHP to read the contents of > a > file > > > from the client's machine?? for eg, the client has a CSV file in his > > > MyDocuments directory, how can I read the contents and publish them > on > the > > > web? > > > > You have to ask them to upload it to the server: > > > > manual > Handling file uploads > > > > -- > > Jason Wong -> Gremlins Associates -> www.gremlins.biz > > Open Source Software Systems Integrators > > * Web Design & Hosting * Internet & Intranet Applications Development > * > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Read file
On Tuesday 18 November 2003 09:58, Ng Hwee Hwee wrote: > the reason i don't want to read from the server is because i don't want to > use up too much space and processing time on the server.. the file has > 50,000 records of information.. > > is there another way other than uploading on the server side?? Two options: 1) You can recompile PHP with the startrek module and use startrek_transport() to instantly transfer anything (data, even physical objects) from anywhere to anywhere else. 2) You can use telepathic means to read the data stored on the client, then type it into a file and save onto the server. But technically speaking, both of the above are still variations of 'uploading' the file onto the server. So another option is: 3) Install a webserver on the client and serve the files from there instead. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* If a program actually fits in memory and has enough disk space, it is guaranteed to crash. -- Murphy's Computer Laws n5 */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Read file
the reason i don't want to read from the server is because i don't want to use up too much space and processing time on the server.. the file has 50,000 records of information.. is there another way other than uploading on the server side?? thanx! hwee - Original Message - From: "Jason Wong" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, November 18, 2003 9:54 AM Subject: Re: [PHP-DB] Read file > On Tuesday 18 November 2003 09:29, Ng Hwee Hwee wrote: > > > can anyone enlighten me on how i can use PHP to read the contents of a file > > from the client's machine?? for eg, the client has a CSV file in his > > MyDocuments directory, how can I read the contents and publish them on the > > web? > > You have to ask them to upload it to the server: > > manual > Handling file uploads > > -- > Jason Wong -> Gremlins Associates -> www.gremlins.biz > Open Source Software Systems Integrators > * Web Design & Hosting * Internet & Intranet Applications Development * -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Read file
On Tuesday 18 November 2003 09:29, Ng Hwee Hwee wrote: > can anyone enlighten me on how i can use PHP to read the contents of a file > from the client's machine?? for eg, the client has a CSV file in his > MyDocuments directory, how can I read the contents and publish them on the > web? You have to ask them to upload it to the server: manual > Handling file uploads -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* QOTD: "My life is a soap opera, but who gets the movie rights?" */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php