In your valued opinions, which is a better programming standard to follow<br><br>I have a maintenance page with SELECT boxes that offer content for a field.<br><br>Let's take states for instance<br><br>With ordinary html or even php printing html, the code would look like
<br><br><select><br> <option value=state_abrv>state_abrv</option><br> {repeat for each state}<br></select><br><br>Pros: No preprocessing at all Cons: HTML is for little girls<br><br>print("<select>\n".
<br>"<option value=\"state_abrv\">state_abrv</option>".<br>{repeat for each state}<br>"</select>");<br><br>Pros: Call to print only once, No need to htmlize the content Cons: Still html
<br><br>A more dynamic approach might be<br><?<br><br>$sql="SELECT st_abrv FROM schema.table-with-st_abrv ORDER BY st_abrv;";<br><br>$result = pg_query($sql) or die("You know that the table doesn't exist); // $dbconn already established by pg_pconnect()
<br><br>print("<select>");<br><br>while ($rows = (pg_fetch_array($result,NULL,PGSQL_ASSOC)) {<br> <br> print("<option value=\"$rows[st_abrv]\">$rows[st_abrv]</option>");<br>
<br>}<br><br>print("</select>");<br><br>pg_free_result($result);<br><br>?><br>Pros: Dynamically generated content, less typing, scalable Cons: More calls to print, More preprocessing <br><br>The first approach seemed okay for things that don't change, although it makes for a lot of typing, which I try to avoid at all costs.
<br>However, it doesn't provide a GUI avenue for adding more options. For states, this probably won't be a problem, but other items may change. Making them available to the maintenance page would require editing the actual code.
<br><br>The second approach offers more dynamics and less typing, but requires more server preprocessing, before the users gets the page their looking for.<br><br>So I ask, which would you prefer?<br> <br clear="all">?>
<br>-- <br>In vino veritas.<br> [In wine there is truth.]<br> -- Pliny