[Looping]- how to Increment the value of i :(

Discussion in 'PHP' started by me4you, Apr 29, 2008.

  1. #1
    In joomla i want a extra value with the subfix

    here is the code

    $menuclass = 'mainlevel' . $params->get('class_sfx');

    it will print

    class ="mainlevel-main-nav"

    but i want mainlevel-main-nav1 mainlevel-main-nav2 mainlevel-main-nav3 and so on...

    but its cant doing :(

    here is the code

    what is for $water.....

    $menuclass = 'mainlevel' . $params->get('class_sfx').$water;
     

    Attached Files:

    me4you, Apr 29, 2008 IP
  2. abixalmon

    abixalmon Well-Known Member

    Messages:
    378
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    120
    #2
    
    $navcount = 1;
    $menuclass = 'mainlevel' . $params->get('class_sfx').$navcount;
    //for (something <= value) {
    //$navcount++;
    // $menuclass = 'mainlevel' . $params->get('class_sfx').$navcount;
    //}
    
    Code (markup):
    Loop something like this should work!!!
     
    abixalmon, Apr 29, 2008 IP
  3. me4you

    me4you Well-Known Member

    Messages:
    1,989
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    155
    #3
    got the following error :(

    Parse error: syntax error, unexpected ')', expecting ';' in C:\wamp\www\xxxxx-2.com\modules\mod_mainmenu\legacy.php on line 113

    :M
     
    me4you, Apr 29, 2008 IP
  4. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #4
    You should have more "arguments" in your for loop:

    
    <?php
    for($navcount = 1; $navcount <= $value;$navcount++){
    $menuclass = 'mainlevel' . $params->get('class_sfx').$navcount;
    }
    ?>
    
    PHP:
    Is a way to do it, or:

    
    <?php
    $navcount = 1;
    while($navcount <= $value){
    $menuclass = 'mainlevel' . $params->get('class_sfx').$navcount;
    $navcount++;
    }
    ?>
    PHP:
     
    blueparukia, Apr 29, 2008 IP
  5. abixalmon

    abixalmon Well-Known Member

    Messages:
    378
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    120
    #5
    something <= value

    Replace something and value with the variable that you want to use!

    LOL :D
     
    abixalmon, Apr 29, 2008 IP
  6. me4you

    me4you Well-Known Member

    Messages:
    1,989
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    155
    #6
    now nothing printing :(

    class="" :(

    <a href="/xxxxxxx-2.com/index.php?option=com_content&amp;view=article&amp;id=1&amp;Itemid=2" class="">about us</a>
     
    me4you, Apr 29, 2008 IP
  7. me4you

    me4you Well-Known Member

    Messages:
    1,989
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    155
    #7
    if (strcasecmp(substr($mitem->link, 0, 4), 'http')) {
    $mitem->url = JRoute::_($mitem->link, true, $menu_secure);
    } else {
    $mitem->url = $mitem->link;
    }

    $menuclass = 'mainlevel' . $params->get('class_sfx');

    if ($level > 0) {
    $menuclass = 'sublevel' . $params->get('class_sfx');
    }
    // replace & with amp; for xhtml compliance
    // remove slashes from excaped characters
    $mitem->name = stripslashes(htmlspecialchars($mitem->name));


    this is the original code
     
    me4you, Apr 29, 2008 IP
  8. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #8
    You did actually change $value to what you what didn't you?

    Wherever I have $value in my script, put it as 10, 100, 3000 or whatever number you want.
     
    blueparukia, Apr 29, 2008 IP