et4891 Posted October 4, 2013 Share Posted October 4, 2013 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 and another page to retrieve the data and make the angles to draw a pie chart. {"angle1":"60","angle2":"60","angle3":"90","submit":"Submit"} The above is what's saved into a row I used <?php $sql = "SELECT * FROM wp_options WHERE option_name LIKE 'angle%' ORDER BY option_name"; $options = $wpdb->get_results($sql); foreach ( $options as $option ) { echo '<p><b>'.$option->option_name.'</b> = ' .esc_attr($option->option_value).'</p>'.PHP_EOL; $line = json_decode($option->option_value, true); } echo '<span style="color:#f00;">'.'Angel 1 : '.$line['angle1'].'</span><br>'; echo '<span style="color:#0f0;">'.'Angel 2 : '.$line['angle2'].'</span><br>'; echo '<span style="color:#00f;">'.'Angel 3 : '.$line['angle3'].'</span><br>'; This prints out angel 1 : ## where ## is the angle entered and so on. I also made a simple 2d piechart which shows the angles. 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. For example in my database I can see {"angle1":"60","angle2":"60","angle3":"90","submit":"Submit"} {"angle1":"60","angle2":"60","angle3":"180","submit":"Submit"} {"angle1":"30","angle2":"60","angle3":"180","submit":"Submit"} 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. Thanks a lot people~ Quote Link to comment Share on other sites More sharing options...
et4891 Posted October 4, 2013 Author Share Posted October 4, 2013 ok I'm so stupid I should have echo those lines inside the foreach loop but then I believe my piechart scripts should be inside the foreach loop too but the thing is my script contains lots of html tags and so on and below is my codes <canvas id="piechart1" width="100" height="100"></canvas> <script src="<?php echo get_stylesheet_directory_uri().'/piechart.js'; ?>"></script> <script> var chartId = "piechart1"; var colours = ["#f00", "#0f0", "#00f"]; var angles = [<?php echo $line['comp2052_angle1'].','. $line['comp2052_angle2'].','. $line['comp2052_angle3']; ?>]; piechart(chartId, colours, angles); </script> how can I implement those codes into foreach easily instead of echo them out bit by bit? Quote Link to comment Share on other sites More sharing options...
Solution et4891 Posted October 4, 2013 Author Solution Share Posted October 4, 2013 nevermind solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.