Is there a more efficient way to run my PHP IF...ELSEIF statement? -


this snippet added shopping cart renders select box 4 choices quantity , refreshes page. originally, there simple input box users use manipulate quantities small cluster of users weren't hitting "update cart" before proceeded checkout decided more proactive. ux practices , ajax methods aside, i'm curious if redundancy of these options necessary in php. how make more efficient?

<select name="quantity" onchange="return updatecart();"> <?php if($this->getqty() == 1) : ?>     <option value="1" selected="selected">1</option>     <option value="2">2</option>     <option value="3">3</option>     <option value="4">4</option> <?php elseif($this->getqty() == 2) : ?>     <option value="1">1</option>     <option value="2" selected="selected">2</option>     <option value="3">3</option>     <option value="4">4</option> <?php elseif($this->getqty() == 3) : ?>     <option value="1">1</option>     <option value="2">2</option>     <option value="3" selected="selected">3</option>     <option value="4">4</option> <?php elseif($this->getqty() == 4) : ?>     <option value="1">1</option>     <option value="2">2</option>     <option value="3">3</option>     <option value="4" selected="selected">4</option> <?php else : ?>     <option value="1">1</option>     <option value="2">2</option>     <option value="3">3</option>     <option value="4">4</option> <?php endif; ?>  </select> 

$quantity = $this->getqty(); for($i=1; $i<=4; $i++){   if($quantity == $i)      echo '<option value="'.$i.'" selected="selected">'.$i.'</option>';   else      echo '<option value="'.$i.'">'.$i.'</option>'; } 

Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -