Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
PHP

Journal yintercept's Journal: No Options

The HTML select tag numbers among the most awkward data structures ever conceived. The select tag lets you present a list of options on a form. You open the tag with a <select> tag. You then send the data for the options in tags of the form <option value="id">display value<option>. Yes, the close tag is required in HTML 4, which does not recognized single tags. You cannot close the tag with a />. You point out the active option by including the valueless attribute "selected" in the option tag for the active value.

I think the mistake of the HTML designers was that they thought of each item in an option list as an item for display, when in practice it is only the selected one.

On analyzing the bandwidth of Community Color, I found that the select tags make up about half the bandwidth consumed by the site. I would not be surprised if a full tenth of all HTML traffic coursing through the net was simply open and shut option tags. The option list containing the ISO database of countries is 10k.

Even worse than the bandwidth waste, I found that over half the database activity was consumed populating option tags. I often do complex joins to show just the right option list and to put the silly little SELECTED attribute next to the selected option.

I can't do anything about the bandwidth consumed by the tags. I think I might be able to reduce the load on the server needed to generate the tags by buffing them in include files. I hadn't done this in the past because I figured I would still have to look through the data line at a time to determine the selected option. What I am trying right now is to buffer the data in a file, then to do a str_replace() to replace the code value="xxx" with value="xxx" selected. My new way for handling select lists is essentially:

//$name is the name of the select variable
//$val is the current value.
//str_replace checks for $chk and replaces with $rep.
$chk='value="'.$val.'"';
$rep='value="'.$val.'" selected';
echo '<select name="'.$name.'">';
echo str_replace($chk, $rep, file_get_contents($file_nm));
echo '</select>';

Reading the buffered file should be faster and take less memory than the database queries. The big question will be to see if it reduces the load on the database server.

It is strange. As I try to upgrade my programs to new standards (UTF-8, XML, HTML Strict), I feel that the signal to noise ratio is increasing exponentially. I so much preferred the days when people gave some thoughts to efficiency. Deep in my heart, I think efficiency is the height of elegance.

This discussion has been archived. No new comments can be posted.

No Options

Comments Filter:

1 + 1 = 3, for large values of 1.

Working...