Jump to content

Building integrated forums to my website


anikwa

Recommended Posts

Well, the forums are the first thing I'm doing but I'm having an error with my SQL.

SELECT * FROM categories_tbl LEFT JOIN forums_tbl ON (forums_tbl.parent_id = categories_tbl.category_id)
WHERE category_id=parent_id

The results of the var_dump: 


array(2) {
  [0]=>
  array(18) {
    ["category_id"]=>
    string(1) "1"
    [0]=>
    string(1) "1"
    ["category_name"]=>
    string(7) "General"
    [1]=>
    string(7) "General"
    ["category_parent_id"]=>
    string(1) "0"
    [2]=>
    string(1) "0"
    ["forum_id"]=>
    string(1) "1"
    [3]=>
    string(1) "1"
    ["forum_name"]=>
    string( "Welcome!"
    [4]=>
    string( "Welcome!"
    ["forum_created"]=>
    string(19) "2013-05-31 18:25:46"
    [5]=>
    string(19) "2013-05-31 18:25:46"
    ["forum_legend"]=>
    string(27) "Introduce yourself in here!"
    [6]=>
    string(27) "Introduce yourself in here!"
    ["parent_id"]=>
    string(1) "1"
    [7]=>
    string(1) "1"
    ["forum_createdby"]=>
    string(7) "Akhaten"
    [8]=>
    string(7) "Akhaten"
  }
  [1]=>
  array(18) {
    ["category_id"]=>
    string(1) "2"
    [0]=>
    string(1) "2"
    ["category_name"]=>
    string(9) "Computers"
    [1]=>
    string(9) "Computers"
    ["category_parent_id"]=>
    string(1) "0"
    [2]=>
    string(1) "0"
    ["forum_id"]=>
    string(1) "2"
    [3]=>
    string(1) "2"
    ["forum_name"]=>
    string(15) "PHP is Awesome!"
    [4]=>
    string(15) "PHP is Awesome!"
    ["forum_created"]=>
    string(19) "2013-05-31 18:25:46"
    [5]=>
    string(19) "2013-05-31 18:25:46"
    ["forum_legend"]=>
    string(18) "Let's all use PHP."
    [6]=>
    string(18) "Let's all use PHP."
    ["parent_id"]=>
    string(1) "2"
    [7]=>
    string(1) "2"
    ["forum_createdby"]=>
    string(5) "xLink"
    [8]=>
    string(5) "xLink"
  }
}
Edited by anikwa
Link to comment
Share on other sites

what error are you having? nothing in your post indicates exactly what is wrong with the result you got v.s. what you expect.

 

the only things I can tell from what you posted is you are repeating the join condition being used in the ON term a second time in the WHERE term, which is just redundant and unnecessary. you are also use a *_fetch_array() statement in your php code and getting both the associative and numerical indexes. since you probably only want the associative indexes, use a *_fetch_assoc() statement.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.