PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I use the following code to populate a dropdown list of state abbreviations in a form. It works fine but is too slow and I want to speed it up. The code also marks the users perviously selected option as the selected option if the forms which use this fail validation. This works but takes too long - about 20 seconds on my server: http://jim.dynalias.net/websales/newaccount.php - and I want to speed it up.
jim_73_mk1 wrote:I use the following code to populate a dropdown list of state abbreviations in a form. It works fine but is too slow and I want to speed it up. The code also marks the users perviously selected option as the selected option if the forms which use this fail validation. This works but takes too long - about 20 seconds on my server: http://jim.dynalias.net/websales/newaccount.php - and I want to speed it up.
odd.. first you can time how long it takes to run the query. then time how long it takes to retrieve the results...
if the first part takes extremely long, get a better mysql server :p
if the second part takes this long, change your query so that it also calculates wether something is selected or not. this way, you offload some cycles from php to mysql.
When trying your script I couldn't get it to function so I rewrote what I had with the ideas in your script. The page now loads in about seven seconds. I think what was happening before was that all the trips between PHP and Apache was slowing it way down. The new version (below) eliminates all that until the html string is completed.
Tim - I actually think the slowness was caused by my poor coding not from a slow server. True though that a faster server would speed things up considerably.
Thanks for your reply and script. I tried it out and it works well, about the same speed as my PHP script. Being that your code has fewer lines (I'm always for fewer lines!) and the added benifit of showing a state on initial load I am using your script for now!