how to add a static number inside a loop, or start from different number inside a loop

Discussion in 'PHP' started by xbat, Aug 22, 2013.

  1. #1
    how to add a static number inside a loop, or start from different number inside a loop..

    $radio_buttons=0
    
    for ($i=0, $n=sizeof ($quotes); $i<$n; $i++) {
    
    
    Code (markup):
    Pretty much my code starts out as

    0 < static
    0 < generated by php
    1
    2
    3


    What I need is my loop to start out at 1 instead of zero.. I tried stuff like '+''.$radiobuttons.'

    But that seems to output a error.

    Thanks
     
    xbat, Aug 22, 2013 IP
  2. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #2
    
    for ($i=1, $n=sizeof ($quotes); $i<$n; $i++) {
    Code (markup):
     
    scottlpool2003, Aug 22, 2013 IP
  3. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #3
    That won't work because of the sizeof rule. Here is more of the code...

     <?php
      //} else {
          $radio_buttons = 0;
          for ($i=0, $n=sizeof($quotes); $i<$n; $i++) {
    ?>
    
          <tr>
            <td colspan="3"><strong><?php echo $quotes[$i]['module']; ?></strong>&nbsp;<?php if (isset($quotes[$i]['icon']) && tep_not_null($quotes[$i]['icon'])) { echo $quotes[$i]['icon']; } ?></td>
          </tr>
    
    <?php
            if (isset($quotes[$i]['error'])) {
    ?>
    
          <tr>
            <td colspan="3"><?php echo $quotes[$i]['error']; ?></td>
          </tr>
    
    <?php
            } else {
              for ($j=0, $n2=sizeof($quotes[$i]['methods']); $j<$n2; $j++) {
    // set the radio button to be checked if it is the method chosen
                $checked = (($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $shipping['id']) ? true : false);
    
                if ( ($checked == true) || ($n == 1 && $n2 == 1) ) {
                 
          echo'         
                <tr id="defaultSelected" class="moduleRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this,0)">' .''. "\n";
                 
    
    //  "\n" hi
       
     
              // <<removed by bt for total over    <td style="padding-left: 15px;">'. PRODUCTS_SHIP_FREE_DESCRIPTION . tep_draw_hidden_field(shipping, free_free).'
              echo'    <td style="padding-left: 15px;">
                  '. sprintf(FREE_SHIPPING_DESCRIPTION, $currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER))
                  .'
                   
    <td>   
    
    
    '.
    //removed // above/\ tep_draw_hidden_field(shipping, free_free) .
    // <td>
         
          $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['id'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))) .'
         
              </td>
    
    
    
    
      <td align="right">'.tep_draw_radio_field(shipping,
        free_free
          // hidden because not needed at this time
          //
          .''.  $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id']
          , $checked)
            .' </td>
    
        </tr>';
                 
                 
    //  double radio button mark.
    //
    //  echo  ' <td align="right">'.tep_draw_radio_field(shipping,
      //        $quotes[$i][id] . '_' . $quotes[$i][methods][$j][id], $checked)
      //      .' </td>';
                 
                 
                 
                  echo '      <tr id="defaultSelected" class="moduleRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this, ' . $radio_buttons . ')">' . "\n";
                } else {
                  echo '      <tr class="moduleRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this, ' . $radio_buttons . ')">' . "\n";
                }
    ?>
    
            <td width="75%" style="padding-left: 15px;"><?php echo $quotes[$i]['methods'][$j]['title']; ?></td>
    
    <?php
                if ( ($n > 1) || ($n2 > 1) ) {
    ?>
    
            <td><?php echo $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))); ?></td>
         
         
            <td align="right"><?php echo tep_draw_radio_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'], $checked); ?> </td>
    
    <?php
                } else {
    ?>
    
            <td align="right" colspan="2"><?php echo $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))) . tep_draw_hidden_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id']); ?></td>
    
    <?php
                }
    ?>
    
          </tr>
    
    <?php
                $radio_buttons++;
              }
          }
        }
      //}
        ?>
    Code (markup):




    see right when it pops out the code it pops out two zeros one after another... which causes the incorrect radio button selection.. If I could start one of those at a 1 then it would work. I would somehow have to add a static one inside my loop.
    "selectRowEffect(this,0)

    
    <tr>
      <td colspan="3"><strong>United Parcel Service (1 pkg x 3 lbs total)</strong>&nbsp;<img src="images/icons/shipping_ups.gif" alt="United Parcel Service" title="United Parcel Service" width="20" height="13" /></td>
      </tr>
    
       
      <tr id="defaultSelected" class="moduleRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this, 0)">
    
      <td style="padding-left: 15px;">Free ground shipping for all of your cart products
       
    
      <td>
       
     $0.00
       
      </td>
    
    
    
    
      <td align="right"><input type="radio" name="shipping" value="free_free" /> </td>
    
      </tr>  <tr id="defaultSelected" class="moduleRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this, 0)">
    
      <td width="75%" style="padding-left: 15px;">UPS Ground (billed dimensional weight 3 LBS)</td>
    
       
       
    
      <td>$9.90</td>
    
    Code (markup):
     
    Last edited: Aug 22, 2013
    xbat, Aug 22, 2013 IP
  4. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #4
    i ended up just rewriting a a bunch of other files and combined a bunch of other items to get it to work.. So I did get my issue solved.. However.. Is what I am wanting to do even possible..? I know you can take a '+'$variable and get it to sort work... This post is jut for curiousity now.
     
    xbat, Aug 22, 2013 IP