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 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    Toronto, Canada
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    while .... Please help

    here is my question .... this might be a bit confusing so please be patient

    what am doing is using while loop to display data from the database, in this case they are categories. the code for this is below...

    <?
    include ('connect.php');
    $query = "SELECT DISTINCT cat FROM product";
    $result = mysql_query( $query, $link );

    while($r=mysql_fetch_array($result))
    {
    $cat=$r['cat'];
    printf ("<span class='body'><b> $cat </b><br><br></span>");
    }
    mysql_free_result($result);
    mysql_close($link);
    ?>

    this works fine ... it lists the categories in this fasion;

    Category1

    Category2

    Category3 and so on ...

    what i want to do is to list also subcategories in in this fasion;

    Category1
    SubCategory1-1, Subcategory1-2

    Category2
    SubCategory2-1, Subcategory2-2

    Category3
    SubCategory3-1, Subcategory3-2

    Do i have to use another while loop to list the subcategories ?
    if so where and how do i put there ?

    Please help ...

    thanx in advance .

    HormonX

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Where are the subcategories listed? - what is the table structure like in the db?

    while($r=mysql_fetch_array($result)) {
    $cat=$r['cat'];
    printf ("<span class='body'><b> $cat </b><br><br></span>");

    $result2 = "SELECT subcategorylist FROM `product` WHERE cat='$cat'";
    while($s = mysql_fetch_array($result2)) {
    $subcat = $s['subcat'];
    echo '<span class="subcat">'.$subcat.'<br>';
    }


    }

    does that help with getting you on track?
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #3
    New Coder
    Join Date
    Aug 2002
    Location
    Toronto, Canada
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thank you

    this helped a whole lot ... i have tried this before .. but i was making a bit of a mistake .. that's why it wasn't working right.

    thanx againg for your help




  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No prob - am glad you found that helpful
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.


  •  

    Posting Permissions

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