Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting an appropriate array using MySQL for PHP
    primarykey
    data
    text
    <p>I have to show a listing of products for a store.All I have is a store id and I have to associate 6 tables to get so. Query I have used is fetching me the records correctly but not in the desirable array format. I don't know if the array format I want is possible or not. My SQL is as follows:</p> <pre><code>SELECT DISTINCT KR.knifename,KR.id,CAT.categoryname,KR.knifecode FROM assocknives AS AK INNER JOIN kniferegisters AS KR ON KR.id = AK.kniferegister_id INNER JOIN categories AS CAT ON CAT.id = KR.sub_category_id INNER JOIN stores AS STR ON STR.id = AK.store_id INNER JOIN brands AS BRND ON BRND.id = AK.brand_id INNER JOIN assocknifeprices AS AKP ON AKP.assocknife_id = AK.id WHERE AK.store_id='.$storeId.' AND BRND.is_active ="1" AND STR.is_active ="1" </code></pre> <p>Which gives me the array as</p> <pre><code>Array ( [0] =&gt; Array ( [KR] =&gt; Array ( [knifename] =&gt; xxx [id] =&gt; xxx [knifecode] =&gt; xxx ) [CAT] =&gt; Array ( [categoryname] =&gt; xxx ) ) [1] =&gt; Array ( [KR] =&gt; Array ( [knifename] =&gt; xxx [id] =&gt; xxx [knifecode] =&gt; xxx ) [CAT] =&gt; Array ( [categoryname] =&gt; xxx ) ) ) </code></pre> <p>The result is correct but I want to get it as</p> <pre><code>Array ( [categoryname1] =&gt; Array ( [0] =&gt; Array ( [knifename] =&gt; xxx [id] =&gt; xxx [knifecode] =&gt; xxx ) [1] =&gt; Array ( [knifename] =&gt; xxx [id] =&gt; xxx [knifecode] =&gt; xxx ) ) [categoryname2] =&gt; Array ( [0] =&gt; Array ( [knifename] =&gt; xxx [id] =&gt; xxx [knifecode] =&gt; xxx ) [1] =&gt; Array ( [knifename] =&gt; xxx [id] =&gt; xxx [knifecode] =&gt; xxx ) ) </code></pre> <p>) I am sorry If this seems to be a silly thing but this array format will really help my cause. Thanks all for your attention.</p>
    singulars
    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.
 

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