Echoing out subcategories and all their items

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ordog
    New Member
    • Aug 2010
    • 1

    Echoing out subcategories and all their items

    sorted now thanks, please delete :)
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    few observation about your mysql database.

    in the table image some columns are unnecessary and problematic
    Code:
    image_id  name  parent    small_img    large_img    cat_id
    name, parent these two columns are already exists in the first table. you do not need to repeat it here. Because you already have a unique id referenced from your first table name cat_id. using cat_id you easily can find out name and parent from table 1 if you need.

    If you want to access row value using column name you need to use
    mysql_fetch_ass oc istead of mysql_fetch_row. follow the example below:
    Code:
    $row=mysql_fetch_row($result);
    
    echo $row['category_id'];//catgory_id must have to pass as string not as constant.
    //this is wrong way
    echo $row[name];//it will make compilation error.
    Getting all the row:
    Code:
    #  $Row = mysql_fetch_array($result);            //get a row of the result, as an array
    #         while($Row) {                                //only while there is data in the row
    #             echo "          <li><a href='index.php?cat=$Row[category_id]'>$Row[name]</a></li>\n";
    #             $Row = mysql_fetch_array($result);        //get next row of results
    #         }
    your code can only access one line. but you need to access every row to process.
    follow the link link. It will give you some good idea about how to get all the row. There is more. But I am little tired to finish all.

    Comment

    Working...