• (cs) in reply to nerdierthanu
    nerdierthanu:
    shadowman:
    bighusker:
    joh6nn:
    from a "time spent" perspective, this copy-paste monstrosity is probably a lot faster than actually good solution.

    I really don't see how this is faster than coding each radio button once and determining if it should be checked within each radio button tag. The only person who would do something this way is a person without any real web development experience.

    $education = array("High School","Some College"); // and so forth
    
    foreach ($education as $ed) {
    	print "<input type='radio' name='EducationID' value='" . $ed . "' ";
    	if ($_SESSION["EducationID"]==$ed) print "checked";
    	print " />" . $ed . "
    "; }

    I didn't know you could do that!

    While that's an entirely acceptable way of doing it, I prefer an alternative which has a little duplication, but I find much easier to read...

    $education = array("High School","Some College"); // and so forth
    
    foreach ($education as $ed) {
    	if ($_SESSION["EducationID"]==$ed) {
    		print "<input type='radio' name='EducationID' value='" . $ed . "' checked />";
    	} else {
    		print "<input type='radio' name='EducationID' value='" . $ed . "' />";
    	}
    }
    

    Granted, if I was doing this in php from scratch, I'd probably use embedded HTML, rather than print statements,

    <?php
    $education = array("High School","Some College"); // and so forth
    
    foreach ($education as $ed) {
    	if ($_SESSION["EducationID"]==$ed) { ?>
    		<input type='radio' name='EducationID' value='<?=$ed?>' checked />";
    <?php	} else { ?>
    		<input type='radio' name='EducationID' value='<?=$ed?>' />";
    <?php	}
    }
    ?>
    
  • nano (unregistered)

    Woah random_garbage, it's amazing how you used PHP to go from elegant to ugly in such a short step. I'd congratulate you, but really I should save the praise for PHP itself.

  • sdfsf (unregistered)

    WTF

Leave a comment on “Only $0.001 per Line”

Log In or post as a guest

Replying to comment #:

« Return to Article