Note that there are some explanatory texts on larger screens.

plurals
  1. POsmall problem in mysql query?
    primarykey
    data
    text
    <p>i have small problem in my sql query</p> <p>my tables</p> <pre><code> /* threads thread_id/thread_title/thread_content 1 / any post title / welcome to my post relations cate_id/thread_id 1 / 1 2 / 1 categories category_id/category_name 1 / some_cate 2 / second_cate */ </code></pre> <p>My sql query</p> <pre><code>$q = mysql_query("SELECT t.*,c.*, GROUP_CONCAT(r.cate_id SEPARATOR ' ') as cate_id FROM threads as t LEFT JOIN relations as r on r.thread_id = t.thread_id LEFT JOIN categories as c on c.category_id = r.cate_id GROUP BY r.thread_id "); </code></pre> <p>php code</p> <pre><code>while($thread = mysql_fetch_array($q)){ echo 'Post title is: ' . $thread['thread_title'] . '&lt;br /&gt;'; // work fine echo 'Post content is: ' . $thread['thread_content'] . '&lt;br /&gt;'; //work fine echo 'Categories id is : ' . $thread['cate_id'] . '/' . '&lt;br /&gt;'; // cate_id of relations table work fine echo 'Categories names is : ' . $thread['category_name'] . '/'; // category name of categories table don't work fine echo '-------End of first POOOOOOOOOOOST--------'; } </code></pre> <p>OUTPUT</p> <pre><code>/* any post title welcome to my post 1/2 some_cate/ -------End of first POOOOOOOOOOOST------- */ </code></pre> <p>Now my problem is!</p> <p>There is small problem in query</p> <p>there is two categories id (1 and 2)</p> <p>should be there is two categories name!</p> <p>some_cate / second_cate</p> <p>but it display only one! though it display two categories id!</p> <p>categories names does not repeat</p> <p>but the categories id is repeat! and working fine</p> <p>@@Doug Kress</p> <p>i tryid your code but there is problem in your code with mysql_fetch_array</p> <p>i got duplication of posts!</p> <pre><code>any post title welcome to my post some_cate/ any post title welcome to my post second_cate/ </code></pre> <p>i am using CONCAT and GROUP BY to avoid this problem </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload