Jump to content

query problems


doddsey_65

Recommended Posts

im trying to group all forums into their respective categories like so:

 

category 1

  forum 1

  forum 2

 

category 2

  forum 3

  forum 4

 

but im having problems with the query:

 

$forum_query = mysqli_query($link, "SELECT cid, c_name, 
                        group_concat(f_name seperator ', ') forums
                        FROM ".TBL_PREFIX."categories
                        LEFT JOIN ".TBL_PREFIX."forums 
                        using (cid)
                        group by ".TBL_PREFIX."categories")
                        or die(mysqli_error($link));

while($forum_info = mysqli_fetch_array($forum_query, MYSQLI_ASSOC))
{
    echo $forum_info['cat_name']."<br>";
    echo $forum_info['forums']."<br>"; 
}

 

i get an sql error before seperator.

 

the database tables are as follows(btw TBL_PREFIX is "asf_")

 

asf_categories

cid    c_name

 

asf_forums

fid    cid    f_name

 

so to summarise im trying to group all foums with cid of 1 into cateogry with cid of 1 and so on.

 

Any pointers?

Link to comment
https://forums.phpfreaks.com/topic/225210-query-problems/
Share on other sites

thanks for the replies. how would i go about not including anything from forums table where the pid != 0?

i tried adding a where clause but it didnt show any categories.

also is this the best way to do this? at the minute for tests im only pulling f_name but i will be wanting to pull alot more from the forum table later. heres my revised code:

 

$forum_query = mysqli_query($link, "SELECT cid, c_name, 
                        group_concat(f_name separator '<br />') forums
                        FROM ".TBL_PREFIX."categories
                        LEFT JOIN ".TBL_PREFIX."forums 
                        USING (cid)
                        GROUP BY ".TBL_PREFIX."categories.cid")
                        or die(mysqli_error($link));

Link to comment
https://forums.phpfreaks.com/topic/225210-query-problems/#findComment-1163125
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.