My query keeps on repeating on my Php script

Discussion in 'PHP' started by John06, Jul 15, 2008.

  1. #1
    im having problem with bullets and queries, what my script does is this:
    Category 1
    • Subcategory 1.1
    • Subcategory 1.2
    • Subcategory 2.1
    • Subcategory 2.2
    Category 2
    • Subcategory 1.1
    • Subcategory 1.2
    • Subcategory 2.1
    • Subcategory 2.2

    What I need is:

    Category 1
    • Subcategory 1.1
    • Subcategory 1.2
    Category 2
    • Subcategory 2.1
    • Subcategory 2.2

    I hope somebody can help me with this...
     
    John06, Jul 15, 2008 IP
  2. ipro

    ipro Active Member

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    you're going to need to post the relevant PHP code, otherwise we can't know what's wrong
     
    ipro, Jul 15, 2008 IP
  3. John06

    John06 Peon

    Messages:
    360
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i do apologize for that...

    here is the script

    $current_cat='';
    $current_cat2='';
    #$result = mysql_query("select job_id,job_name,job_desc from job_category, subcategories where job_category.job_id = subcategories.subcategory_id") or die("SELECT Error: ".mysql_error());
    $result = mysql_query("SELECT * FROM job_category")
    or die("SELECT Error: ".mysql_error());
    while($row = mysql_fetch_assoc($result))
    {
    if ($current_cat != $row['job_name'])
    {
    // dont print the end of the table on the first loop
    if(!empty($current_cat))
    {
    echo '</table>';
    }
    $current_cat = $row['job_name'];
    echo '<table width=100% border=0 cellspacing=0 cellpadding=0>';
    echo '<tr><td><b>' .$row["job_name"]. '</b></td></tr>';
    echo '<tr><td>' .$row["job_desc"]. '</td></tr>';
    $result2 = mysql_query("SELECT * FROM job_category, subcategories WHERE job_subcat = job_id") or die(mysql_error());
    while ($row2 = mysql_fetch_assoc ($result2))
    {
    if ($current_cat2 != $row2['subcategory_name'])
    {
    // dont print the end of the table on the first loop
    if(!empty($current_cat2))
    {
    echo '</table>';
    }
    echo '<tr><td>' .$row2["subcategory_name"]. '</td></tr>';
    }}
    echo '<tr><td>&nbsp;</td></tr>';
    echo '</table>';
    }
    }

    ?>
     
    John06, Jul 16, 2008 IP
  4. John06

    John06 Peon

    Messages:
    360
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Let me add that i use two tables on my database
     
    John06, Jul 16, 2008 IP