- Nov 18, 2004
- 945
- 0
- 76
I was wondering if it is possible to update the contents of a php file or a JS file without having to reload the entire file again.
What I am working on is a group of select boxes that are "chained" or dynamically update based on what the user selects in a given box.
The 'parent box' is the "User" box, which has a child, "Book", who has a child, "Chapter" who has a child, "Verse".
when you click on User, the other boxes update according to that, so if user is changed to 'joe', then the books load for 'joe', and the chapters of the first book in the option list load in chapter, and the verses in the first chapter load in verse. When the user selects a verse, the verse loads in a div box via a MySQL request.
The problem that I am having though is my verses alone total 1,344. It isn't really a problem when the page loads, because of connection speeds, but I don't want it to turn into an issue, and I don't want to neglect anyone who might have dial up.
How this page was originally set up was with a JavaScript library that would do all of the dynamic updating for the boxes, and it did it nicely too. I wouldn't run into problems with the child boxes not repopulating properly automatically and properly.
When I made it possible for there to be multiple users though, I switched over to using php and MySQL only. This was great because I didn't have the overhead of the JS library and it cut the file size down to 3k instead of 66k.
So what I want to do though, is use both the JS and the PHP/MySQL at the same time.
I don't really know how everything works, and I don't have a lot of time because of my living conditions (I'm in the Philippines doing an internship), but here is what I was thinking about doing.
I want to use a select statement as the condition for loading the specific for the specific user. The default will be the originally selected user in the user box, that will be completely loaded when the page loads.
I would like to have a PHP function that is trigged for both onclick and onchange in the 'User' select box.
what the function will do is check to see if the user is in the list of users that have already been loaded. If it is the first time the user box has been changed, then the list will be empty except for the default.
the pseudo code will look something like
$gotoSwitch=0;
while($counter>$arrayLen) if($user==$usersLoaded[$counter]) $gotoSwitch=1;
if(!$gotoSwitch) appendData($user);
switch($user)
{
include(userdata.php)
default:
//default data
}
appendData($user)
{
//searches mysql for select box info
//appends userdata.php
}
Now, I'm sure that there are a few bugs in the code, and that is all good and well, it will get ironed out in the process. But I was wondering if there was a way I could do this with JS too. I think that the PHP might cause the file to be downloaded each time, but I think if I can do this with JS, then I would be on the client side. But I might not even know what I'm talking about...
I am looking into how cookies work. Because I honestly don't know anything about them, and if I could do this with a cookie, then maybe it would be a decent route to take.
The whole point to this is to cut down the total loading/reloading time and to give the illusion that things are there when they aren't.
If I can get this to work, then I would like to have a few functions that go around in the background that grab the data so that the user won't notice the loading times at all.
What I am working on is a group of select boxes that are "chained" or dynamically update based on what the user selects in a given box.
The 'parent box' is the "User" box, which has a child, "Book", who has a child, "Chapter" who has a child, "Verse".
when you click on User, the other boxes update according to that, so if user is changed to 'joe', then the books load for 'joe', and the chapters of the first book in the option list load in chapter, and the verses in the first chapter load in verse. When the user selects a verse, the verse loads in a div box via a MySQL request.
The problem that I am having though is my verses alone total 1,344. It isn't really a problem when the page loads, because of connection speeds, but I don't want it to turn into an issue, and I don't want to neglect anyone who might have dial up.
How this page was originally set up was with a JavaScript library that would do all of the dynamic updating for the boxes, and it did it nicely too. I wouldn't run into problems with the child boxes not repopulating properly automatically and properly.
When I made it possible for there to be multiple users though, I switched over to using php and MySQL only. This was great because I didn't have the overhead of the JS library and it cut the file size down to 3k instead of 66k.
So what I want to do though, is use both the JS and the PHP/MySQL at the same time.
I don't really know how everything works, and I don't have a lot of time because of my living conditions (I'm in the Philippines doing an internship), but here is what I was thinking about doing.
I want to use a select statement as the condition for loading the specific for the specific user. The default will be the originally selected user in the user box, that will be completely loaded when the page loads.
I would like to have a PHP function that is trigged for both onclick and onchange in the 'User' select box.
what the function will do is check to see if the user is in the list of users that have already been loaded. If it is the first time the user box has been changed, then the list will be empty except for the default.
the pseudo code will look something like
$gotoSwitch=0;
while($counter>$arrayLen) if($user==$usersLoaded[$counter]) $gotoSwitch=1;
if(!$gotoSwitch) appendData($user);
switch($user)
{
include(userdata.php)
default:
//default data
}
appendData($user)
{
//searches mysql for select box info
//appends userdata.php
}
Now, I'm sure that there are a few bugs in the code, and that is all good and well, it will get ironed out in the process. But I was wondering if there was a way I could do this with JS too. I think that the PHP might cause the file to be downloaded each time, but I think if I can do this with JS, then I would be on the client side. But I might not even know what I'm talking about...
I am looking into how cookies work. Because I honestly don't know anything about them, and if I could do this with a cookie, then maybe it would be a decent route to take.
The whole point to this is to cut down the total loading/reloading time and to give the illusion that things are there when they aren't.
If I can get this to work, then I would like to have a few functions that go around in the background that grab the data so that the user won't notice the loading times at all.
