SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    49
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question how to code with this?

    i design my website as below
    +tbl_menu
    -menu_id
    -menu_name (news | tips| reviews )
    ...................
    +tbl_sub_menu
    -sub_id
    -menu_id
    -sub_name (phone,tablet,laptop.......)
    ...............
    +tbl_article
    -art_id
    -menu_name
    -sub_name
    -art_title
    .....................
    SELECT
    `tbl_sub_menu`.`sub_name`,
    `tbl_article`.`menu_name`,
    `tbl_article`.`art_title`,
    `tbl_article`.`menu_name`
    FROM
    tbl_sub_menu, tbl_article
    WHERE
    `tbl_sub_menu`.`sub_name` = `tbl_article`.`sub_name`
    AND
    `tbl_article`.`menu_name` = 'tips'
    .......................................
    how gonna code like that

    SELECT
    `tbl_sub_menu`.`sub_name`,
    `tbl_article`.`menu_name`,
    `tbl_article`.`art_title`,
    `tbl_article`.`menu_name`
    FROM
    tbl_sub_menu, tbl_article
    WHERE
    `tbl_sub_menu`.`sub_name` = 'laptop'
    AND
    `tbl_article`.`menu_name` = 'tips'

    so the url might look like this
    example.com/index.php?menu_name=tips&sub_name=laptop
    anybody give me some light?

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Does a submenu item such as `laptop` only ever appear in one main menu?

  3. #3
    Non-Member
    Join Date
    Oct 2007
    Posts
    363
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hengwebdeveloper View Post
    i design my website as below
    +tbl_menu
    -menu_id
    -menu_name (news | tips| reviews )
    ...................
    +tbl_sub_menu
    -sub_id
    -menu_id
    -sub_name (phone,tablet,laptop.......)
    ...............
    +tbl_article
    -art_id
    -menu_name
    -sub_name
    -art_title
    .....................
    SELECT
    `tbl_sub_menu`.`sub_name`,
    `tbl_article`.`menu_name`,
    `tbl_article`.`art_title`,
    `tbl_article`.`menu_name`
    FROM
    tbl_sub_menu, tbl_article
    WHERE
    `tbl_sub_menu`.`sub_name` = `tbl_article`.`sub_name`
    AND
    `tbl_article`.`menu_name` = 'tips'
    .......................................
    how gonna code like that

    SELECT
    `tbl_sub_menu`.`sub_name`,
    `tbl_article`.`menu_name`,
    `tbl_article`.`art_title`,
    `tbl_article`.`menu_name`
    FROM
    tbl_sub_menu, tbl_article
    WHERE
    `tbl_sub_menu`.`sub_name` = 'laptop'
    AND
    `tbl_article`.`menu_name` = 'tips'

    so the url might look like this
    example.com/index.php?menu_name=tips&sub_name=laptop
    anybody give me some light?
    There's literally no point in the "tbl_" prefix, so just get rid of it.

    You'll make your database easier to read if you remove the differing names for id fields too - you've got menu_id as the id field for the menu table, but art_id as the id field for articles. This is going to make it harder to remember for yourself going forward.

    A much better convention is to simply name your id fields as "id" in every table, and then to name foreign keys by the name of the table you're referencing, followed by "_id".

    So the same table structure would now look like:

    menus
    -id
    -name (news | tips| reviews )
    ...................
    +sub_menus
    -id
    -menu_id
    -name (phone,tablet,laptop.......)
    ...............
    +articles
    -id
    -menu_name
    -sub_name
    -title
    .....................

    I'm not sure what the "menu_name" and "sub_name" fields are for in your article table, but this database structure suddenly looks much cleaner, don't you think?

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Cups View Post
    Does a submenu item such as `laptop` only ever appear in one main menu?
    Maybe the OP only needs one table.


Bookmarks

Posting Permissions

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