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

    Join Date
    Aug 2000
    Colombo, Western, Sri Lanka
    Rep Power
    categories table info :

    id: unique auto increment
    parent_id: all master categories =0
    sub categories = id of its master category
    name : name of category

    The script I've written is supposed to each master category in the table followed immediately by any sub-categories it may have. If a particular master category does not have any subcategories it should fetch the next master category.

    My script works fine up to the point where the table contains a few subcategories before the next master category. At this point it lists out the subcategory (which has already been listed earlier within a master category) again assuming that it is a master category.

    All I need if an if or while statement in my script. I've tried different variations, but nothing worked.

    Here's the script :

    $result = mysql("select * from categories where id!=0");
    $num = mysql_numrows($result);
    $i = 0;

    while($i < $num) {

    echo "<p>";

    echo mysql_result($result,$i,"name");

    echo "<p>";


    $subcategory=mysql_query("select name from categories where parent_id=$pid");



    while ($j<$num2){

    echo "<p>";

    print ("&nbsp;&nbsp;&nbsp;");

    echo mysql_result($subcategory,$j,"name");





    This is what I have in my mind.

    Immediately after the first 'while' there should be something like this :


    if ($parent=0) :

    and just before $i++:}


    That's the idea. But it doesn't work. I get a blank screen.

    Somebody please help me

    Thanks a lot to anyone who will be able to help me out.

  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Rep Power
    Have you tried, in the SQL statement, WHERE id IS NOT NULL rather than the !=0?

    [This message has been edited by leaed (edited September 06, 2000).]

Similar Threads

  1. php script won't work inside "cgi-local" directory
    By Volitics in forum PHP Development
    Replies: 5
    Last Post: April 26th, 2004, 10:50 PM
  2. Replies: 2
    Last Post: February 10th, 2004, 11:03 PM
  3. mod_rewrite and Apache 2 cgi script not working
    By jroamo in forum Apache Development
    Replies: 0
    Last Post: February 10th, 2004, 12:22 PM
  4. Trying to call cgi script onunload via image.src
    By oscarf in forum HTML Programming
    Replies: 3
    Last Post: February 6th, 2004, 10:18 PM
  5. How can I enable a power user to run this script?
    By Yamadatroy in forum Visual Basic Programming
    Replies: 2
    Last Post: January 19th, 2004, 09:39 PM

IMN logo majestic logo threadwatch logo seochat tools logo