Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: Pulling JSON data out of database and displaying it
    primarykey
    data
    text
    <p>I'm using a php library from <a href="https://sourceforge.net/p/wowarmoryapi/home/Home/" rel="nofollow noreferrer">https://sourceforge.net/p/wowarmoryapi/home/Home/</a>. It pulls json data from battle.net and stores it in my database for cache reasons.</p> <p>code to get json from db (I'm not sure if it's still considered json at this point):</p> <pre><code>$data = $con-&gt;query('SELECT Data FROM wa_guilds'); </code></pre> <p>I use the following code to see the data:</p> <pre><code>foreach($data as $row) { echo "&lt;span style='color:#ff0099'&gt;"; var_dump($row); echo "&lt;/span&gt;"; } </code></pre> <p>which looks like this minus the errors, that's from another code: <img src="https://i.stack.imgur.com/x3ial.jpg" alt="pink text is the dump"></p> <p>I've tried various methods, mostly from this site to show my data in a way that's easy to read but I always get error. </p> <ol> <li>This is definitely an object. <code>if (is_object($data)) { echo "yay!"; }</code> &lt;--this works</li> <li>Once I use <code>$decodedjson = json_decode($data);</code> it's no longer an object and I can't seem to print the results to see what it looks like. var_dump($decodedjson) returns NULL</li> </ol> <p>Finally, when I use the following code:</p> <pre><code>foreach ($data as $da){ echo $da['Data']['character']['name']; } </code></pre> <p>returns <b>Warning: Illegal string offset 'character'</b></p> <p>and:</p> <pre><code>foreach ($data as $da){ echo $da['character']['name']; } </code></pre> <p>returns <b>Notice: Undefined index: character</b></p> <p>I don't understand what I'd doing wrong, or right. Do I need to somehow turn $data into a string?</p> <h2>NEW CODE</h2> <pre><code>$sth = $con-&gt;query('SELECT Data FROM wa_guilds'); $sth-&gt;execute(); $data = $sth-&gt;fetchAll(PDO::FETCH_ASSOC); foreach($data as $row) { foreach($row as $r) { $myData = json_decode($r, true); echo "&lt;span style='color:#ff0099'&gt;"; var_dump($myData['Data']); echo "&lt;/span&gt;"; } } </code></pre> <h2>NEW ERROR</h2> <p>NULL NULL</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