Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Jun 2003
    Posts
    7
    Member #
    1764
    If there is any way to optimize the following two sets of code, I would very much appreciate your help in doing so.

    Code:
    $expire_hours.="<option value=\"0\">0 Hours</option>";
    $expire_hours.="<option value=\"1\" selected>1 Hour</option>";
    $expire_hours.="<option value=\"2\">2 Hours</option>";
    $expire_hours.="<option value=\"3\">3 Hours</option>";
    $expire_hours.="<option value=\"4\">4 Hours</option>";
    $expire_hours.="<option value=\"5\">5 Hours</option>";
    $expire_hours.="<option value=\"6\">6 Hours</option>";
    $expire_hours.="<option value=\"7\">7 Hours</option>";
    $expire_hours.="<option value=\"8\">8 Hours</option>";
    $expire_hours.="<option value=\"9\">9 Hours</option>";
    $expire_hours.="<option value=\"10\">10 Hours</option>";
    $expire_hours.="<option value=\"11\">11 Hours</option>";
    $expire_hours.="<option value=\"12\">12 Hours</option>";
    $expire_hours.="<option value=\"13\">13 Hours</option>";
    $expire_hours.="<option value=\"14\">14 Hours</option>";
    $expire_hours.="<option value=\"15\">15 Hours</option>";
    $expire_hours.="<option value=\"16\">16 Hours</option>";
    $expire_hours.="<option value=\"17\">17 Hours</option>";
    $expire_hours.="<option value=\"18\">18 Hours</option>";
    $expire_hours.="<option value=\"19\">19 Hours</option>";
    $expire_hours.="<option value=\"20\">20 Hours</option>";
    $expire_hours.="<option value=\"21\">21 Hours</option>";
    $expire_hours.="<option value=\"22\">22 Hours</option>";
    $expire_hours.="<option value=\"23\">23 Hours</option>";

  2.  

  3. #2
    Senior Member mossoi's Avatar
    Join Date
    Apr 2003
    Location
    Englandshire, United Kingdomsville y'all!
    Posts
    1,111
    Member #
    1206
    Liked
    1 times
    Below is the code for the first snippet you posted. I've not done the second but it should be fairly obvious how to convert it using the code below.

    The for loop takes three arguments, $i = 0 determines the starting number, $i <= 30 is the limit for the loop and $i++ increments $i for each loop.

    Code:
    <?
    $expire_hours = "<select>";
    for ($i = 0; $i <= 30; $i++) {
    	$expire_hours.="<option value=\"$i\">$i Hours</option>";
    }
    $expire_hours .= "</select>";
    echo $expire_hours;
    ?>

  4. #3
    Junior Member
    Join Date
    Jun 2003
    Posts
    7
    Member #
    1764
    Excellent! Thanks. It makes sense now.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:50 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com