Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to print out all certian json data in database?
    primarykey
    data
    text
    <p>What I'm trying is I have a page which you can input 3 angel integers and submit. After you submit the data will be saved in database using json encode</p> <pre><code>{"angle1":"60","angle2":"60","angle3":"90","submit":"Submit"} </code></pre> <p>The above is what's saved into a row</p> <p>I used</p> <pre><code>&lt;?php $sql = "SELECT * FROM wp_options WHERE option_name LIKE 'angle%' ORDER BY option_name"; $options = $wpdb-&gt;get_results($sql); foreach ( $options as $option ) { echo '&lt;p&gt;&lt;b&gt;'.$option-&gt;option_name.'&lt;/b&gt; = ' .esc_attr($option-&gt;option_value).'&lt;/p&gt;'.PHP_EOL; $line = json_decode($option-&gt;option_value, true); } echo '&lt;span style="color:#f00;"&gt;'.'Angel 1 : '.$line['angle1'].'&lt;/span&gt;&lt;br&gt;'; echo '&lt;span style="color:#0f0;"&gt;'.'Angel 2 : '.$line['angle2'].'&lt;/span&gt;&lt;br&gt;'; echo '&lt;span style="color:#00f;"&gt;'.'Angel 3 : '.$line['angle3'].'&lt;/span&gt;&lt;br&gt;'; </code></pre> <p>This prints out angel 1 : ## where ## is the angle entered and so on. I also made a simple 2d piechart which shows the angles.</p> <p>the problem I'm having is if I submit another 3 angles then my result only shows the MOST RECENT angles entered even if there are two or more in the database.</p> <p>For example in my database I can see</p> <pre><code>{"angle1":"60","angle2":"60","angle3":"90","submit":"Submit"} {"angle1":"60","angle2":"60","angle3":"180","submit":"Submit"} {"angle1":"30","angle2":"60","angle3":"180","submit":"Submit"} </code></pre> <p>but the result only prints 30 60 and 180 instead of printing all three. Anyone mind giving me a hand on how I can print all three data out or at least all three sets of the angles. I believe once I figured that out I can then print out all the piecharts with all the angles instead right now only the most recent angle and the piechart are printed.</p> <p>Thanks a lot people~</p> <p>P.S.</p> <p>I'm so so so stupid I didn't put those echo into the foreach loop but my other question is I believe I need to input my codes below into the foreach loop but there are so many tags is there a way to input all those into the foreach loop instead of doing something like echo canvas id="piechart1" blah blah blah and do it bit by bit?</p> <pre><code>&lt;canvas id="piechart1" width="100" height="100"&gt;&lt;/canvas&gt; &lt;script src="&lt;?php echo get_stylesheet_directory_uri().'/piechart.js'; ?&gt;"&gt;&lt;/script&gt; &lt;script&gt; var chartId = "piechart1"; var colours = ["#f00", "#0f0", "#00f"]; var angles = [&lt;?php echo $line['comp2052_angle1'].','. $line['comp2052_angle2'].','. $line['comp2052_angle3']; ?&gt;]; piechart(chartId, colours, angles); &lt;/script&gt; </code></pre>
    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.
    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