Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON data encoded are repeated
    primarykey
    data
    text
    <p>I have a database with several data in it, but they are unique of course. These data are inside each table, <strong>telcoCall</strong>, <strong>telcoData</strong>, <strong>telcoSMS</strong>, depending on its class.</p> <p>I then use <code>json_encode</code> to merge these data into 1 single array. Inside <strong>telcoCall</strong>, the data are in proper place. However, <strong>telcoData</strong> and <strong>telcoSMS</strong> are messy. The data inside these tables are being duplicated. This is how it looks,</p> <p><img src="https://i.imgur.com/Sbg3ctN.png" alt="enter image description here"></p> <p>Here's the code:</p> <pre><code>&lt;?PHP include '../initialization.php'; $mysqli = @mysqli_connect($host, $username, $password, $db); $query = 'SELECT t.*, c.*, d.*, s.* '. 'FROM telco t '. 'INNER JOIN telcoCall c ON t.telcoId = c.telcoId '. 'INNER JOIN telcoData d ON t.telcoId = d.telcoId '. 'INNER JOIN telcoSMS s ON t.telcoId = s.telcoId '. 'ORDER BY t.telcoName, c.callName, d.dataName, s.smsName'; //setup array to hold information $telcos = array(); //setup holders for the different types so that we can filter out the data $telcoId = 0; $callId = 0; $dataId = 0; $smsId = 0; //setup to hold our current index $telcoIndex = -1; $callIndex = -1; $dataIndex = -1; $smsIndex = -1; if ($result = mysqli_query($mysqli, $query)) { //go through the rows while($row = mysqli_fetch_assoc($result)) { if($telcoId != $row['telcoId']) { $telcoIndex++; $callIndex = -1; $dataIndex = -1; $smsIndex = -1; $telcoId = $row['telcoId']; //add the console $telcos[$telcoIndex]['Telco'] = $row['telcoName']; //setup the information array $telcos[$telcoIndex]['Call Promo'] = array(); $telcos[$telcoIndex]['Data Promo'] = array(); $telcos[$telcoIndex]['SMS Promo'] = array(); } if($callId != $row['callId']) { $callIndex++; $callId = $row['callId']; //add the model to the console $telcos[$telcoIndex]['Call Promo'][$callIndex]['Call Name'] = $row['callName']; //setup the title array $telcos[$telcoIndex]['Call Promo'][$callIndex]['Call'] = array(); //add the game to the current console and model $telcos[$telcoIndex]['Call Promo'][$callIndex]['Call'][] = array( 'Keyword' =&gt; $row['callKeyword'], 'Description' =&gt; $row['callDescription'], 'Number' =&gt; $row['callNumber'], 'Validity' =&gt; $row['callValidity'], 'Price' =&gt; $row['callPrice'] ); } if($dataId != $row['dataId']) { $dataIndex++; $dataId = $row['dataId']; //add the model to the console $telcos[$telcoIndex]['Data Promo'][$dataIndex]['Data Name'] = $row['dataName']; //setup the title array $telcos[$telcoIndex]['Data Promo'][$dataIndex]['Data'] = array(); //add the game to the current console and model $telcos[$telcoIndex]['Data Promo'][$dataIndex]['Data'][] = array( 'Keyword' =&gt; $row['dataKeyword'], 'Description' =&gt; $row['dataDescription'], 'Number' =&gt; $row['dataNumber'], 'Validity' =&gt; $row['dataValidity'], 'Volume' =&gt; $row['dataVolume'], 'Price' =&gt; $row['dataPrice'] ); } if($smsId != $row['smsId']) { $smsIndex++; $smsId = $row['smsId']; //add the model to the console $telcos[$telcoIndex]['SMS Promo'][$smsIndex]['SMS Name'] = $row['smsName']; //setup the title array $telcos[$telcoIndex]['SMS Promo'][$smsIndex]['SMS'] = array(); //add the game to the current console and model $telcos[$telcoIndex]['SMS Promo'][$smsIndex]['SMS'][] = array( 'Keyword' =&gt; $row['smsKeyword'], 'Description' =&gt; $row['smsDescription'], 'Number' =&gt; $row['smsNumber'], 'Validity' =&gt; $row['smsValidity'], 'Price' =&gt; $row['smsPrice'] ); } } mysqli_free_result($result); } echo json_encode($telcos); mysqli_close($mysqli); ?&gt; </code></pre> <p>I really don't know why this is happening.</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.
    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