#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    15
    The good news is that there are no errors, but the breaks between each $brand aren't printing as I planned (at all).

    I am trying to have a two breaks between each brand (with each brand having multiple $modelletters):

    Honda CR
    Honda XL
    Honda XR

    Yamaha YZ
    Yamaha WR

    Suzuki RM
    Suzuki DR
    Suzuki SP

    And so on...

    Here's what I have now:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $result = mysql_query("SELECT brand, COUNT(*) FROM spec GROUP BY brand",$db);

    while ($myrow = mysql_fetch_array($result)) {

    $result2 = mysql_query("SELECT brand, modelletters, COUNT(*) FROM spec GROUP BY modelletters",$db);

    while ($myrow = mysql_fetch_array($result2)) {

    printf("%s", $myrow['brand']);
    echo "&nbsp;";
    printf("%s", $myrow['modelletters']);
    echo "<br>";

    }

    echo "<br>";

    }[/code]
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,643
    Rep Power
    4492
    I've tried nested queries like this before and they never seem to work for some reason. Here is something you could try...(i took out the count(*), i didn't see where you were using that)

    $loops = 0;
    $result = mysql_query("SELECT brand, modelletters FROM spec GROUP BY modelletters",$db);
    while ($myrow = mysql_fetch_array($result2)) {
    printf("%s", $myrow['brand']);
    $brand = $myrow['brand'];
    echo " ";
    printf("%s", $myrow['modelletters']);
    echo "<br>";
    if ($loops > 0 && $brand != $old_brand)
    {
    echo "<BR>n";
    }
    $loops++;
    $old_brand = $brand;
    }

    I think that'll work. Don't have a system to check it on right now, but hopefully you get the idea..

    ---John Holmes...
  4. #3
  5. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<
    if ($loops > 0 && $brand != $old_brand)
    {
    echo "<BR>n";
    }
    $loops++;
    $old_brand = $brand;
    }
    >>

    yea,
    The above will give a break between the each $brand.also you need only one query.
    $result = mysql_query("SELECT brand, modelletters FROM spec GROUP BY modelletters",$db);

    $count=mysql_num_rows($result);

    echo "Total: $countn";

    while ($myrow = mysql_fetch_array($result)) {

    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited August 31, 2000).]

Similar Threads

  1. How to clear a string in a loop??
    By Gecko22 in forum ASP Programming
    Replies: 2
    Last Post: January 23rd, 2004, 01:35 PM
  2. A mixed foreach loop
    By Datamike in forum Dev Shed Lounge
    Replies: 11
    Last Post: December 17th, 2003, 08:40 PM
  3. Replies: 7
    Last Post: October 10th, 2003, 08:13 AM
  4. Getting results from one loop into another loop
    By camcim in forum PHP Development
    Replies: 1
    Last Post: September 26th, 2003, 08:26 AM
  5. pointer array in while loop
    By ppp0 in forum C Programming
    Replies: 4
    Last Post: September 1st, 2003, 09:17 AM

IMN logo majestic logo threadwatch logo seochat tools logo