Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: increment count

  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    increment count

    Hey guys I need some help, Im trying to generate a numbered list by using i++ and an if statement but I cant seem to get the values to start over to 0, here is a look at my code
    Code:
    $make = "SELECT * FROM category_description ORDER BY category_id ASC LIMIT 1000";
    $makeresult = mysql_query($make);
    while($make1 = mysql_fetch_array($makeresult)){
      $parent = "SELECT * FROM category WHERE parent_id = {$make1['category_id']} LIMIT 1000";
    $parentresult = mysql_query($parent);
    while($parent1 = mysql_fetch_array($parentresult)){
        if(($make1['category_id'] == $parent1['parent_id']) AND ($make1['name'] == $make1['name'])){
     $i += 1;
      $count = $i;
     echo "[". $count . "]" . " " . $parent1['category_id'] . " " . $make1['category_id'] . " " . $parent1['parent_id'] . " " . $make1['name'] . "<br />";
    Basically the output comes out like this:
    Code:
    [1] 100 10 10 Acura
    [2] 101 10 10 Acura
    [3] 102 10 10 Acura
    [4] 103 10 10 Acura
    [5] 104 10 10 Acura
    [6] 105 10 10 Acura
    [7] 106 10 10 Acura
    [8] 107 10 10 Acura
    [9] 108 10 10 Acura
    [10] 109 10 10 Acura
    [11] 110 10 10 Acura
    [12] 111 10 10 Acura
    [13] 112 10 10 Acura
    [14] 113 10 10 Acura
    [15] 126 11 11 Audi
    [16] 127 11 11 Audi
    [17] 128 11 11 Audi
    [18] 129 11 11 Audi
    [19] 130 11 11 Audi
    [20] 131 11 11 Audi
    [21] 132 11 11 Audi
    [22] 133 11 11 Audi
    [23] 134 11 11 Audi
    [24] 135 11 11 Audi
    [25] 136 11 11 Audi
    [26] 137 11 11 Audi
    But I need it to come out like this, so basically if Acura = Acura generate 1,2,3,4 etc and if Audi = Audi generate 1,2,3,4......Im still somewhat new to this would really appreciate the help if someone can point me in the right direction:
    Code:
    [1] 100 10 10 Acura
    [2] 101 10 10 Acura
    [3] 102 10 10 Acura
    [4] 103 10 10 Acura
    [5] 104 10 10 Acura
    [6] 105 10 10 Acura
    [7] 106 10 10 Acura
    [8] 107 10 10 Acura
    [9] 108 10 10 Acura
    [10] 109 10 10 Acura
    [11] 110 10 10 Acura
    [12] 111 10 10 Acura
    [13] 112 10 10 Acura
    [14] 113 10 10 Acura
    [1] 126 11 11 Audi
    [2] 127 11 11 Audi
    [3] 128 11 11 Audi
    [4] 129 11 11 Audi
    [5] 130 11 11 Audi
    [6] 131 11 11 Audi
    [7] 132 11 11 Audi
    [8] 133 11 11 Audi
    [9] 134 11 11 Audi
    [10] 135 11 11 Audi
    [11] 136 11 11 Audi
    [12] 137 11 11 Audi
    I cant seem to figure this out, would appreciate any help.
    Thanks

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,300
    Thanks
    4
    Thanked 203 Times in 200 Posts
    Added $i = 0 before your inner while and removed the use of $count completely since you're not using $i for anything else there was no need to create/use another variable.

    PHP Code:
    $make "SELECT * FROM category_description ORDER BY category_id ASC LIMIT 1000";
    $makeresult mysql_query($make);
    while(
    $make1 mysql_fetch_array($makeresult)){
      
    $parent "SELECT * FROM category WHERE parent_id = {$make1['category_id']} LIMIT 1000";
    $parentresult mysql_query($parent);
    $i 0;
    while(
    $parent1 mysql_fetch_array($parentresult)){
        if((
    $make1['category_id'] == $parent1['parent_id']) AND ($make1['name'] == $make1['name'])){
     
    $i++;
     echo 
    "["$i "]" " " $parent1['category_id'] . " " $make1['category_id'] . " " $parent1['parent_id'] . " " $make1['name'] . "<br />"
    Dave .... HostMonster for all of your hosting needs


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •