Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6943471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:09:37+00:00 2026-05-27T13:09:37+00:00

Im trying to learn php by doing a little project using apache server. I

  • 0

Im trying to learn php by doing a little project using apache server. I have a php page where I want to display a bar chart with jqplot using data i pull from a MySql query. I already have a query working giving me the data i want. The problem is i dont know how to implement this into a jqplot graph. Im guessing i need to make an ajax call but if i can avoid that i would like to. my php page code so far is here http://snipt.org/oknnl2.
the javascript for the bar chart is here http://snipt.org/oknoi3.
i want the chart to render in div id=chartdiv thats on line 177. I have to visualize like 6 charts. if i can get some help on doing this one, im sure i can use the same process to build the others.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:09:38+00:00Added an answer on May 27, 2026 at 1:09 pm

    PHP cannot create the javascript plot and send it downstream to the client, but you don’t have to make an actual AJAX call after the page is loaded either. Simple javascript once the page loads will suffice. If you retrieve the data you need at the PHP level, you can then make it available to javascript in the HTML received by the client. The steps to make this happen:

    1. First, use PHP to retrieve the data you need from the MySQL database.
    2. Then, output the plot data you retrieved using PHP inside a javascript
      code block as part of the HTML that PHP sends to the client.
    3. Execute the javascript with the data seeded by PHP on page load.

    So, a simplified example:

    <?php
    
    // Retrieve plot data from mysql
    $q = '...';
    $r = mysql_query($q);
    
    $plot_row1 = array();
    $plot_row2 = array();
    $plot_row3 = array();
    
    while ($row = mysql_fetch_array($r)) {
        // append values to $plot_row1, $plot_row2 and $plot_row3 arrays
    }
    
    $my_page_title = 'My first PHP/JS Combo Foray';
    
    ?>
    
    <html>
    <head>
        <script type="text/javascript" src="/scripts/jquery-1.5.2.min.js"></script>
        <script type="text/javascript" src="/scripts/my_plotter.js"></script>
    </head>
    <body>
    
    <h1><?php echo $my_page_title; ?></h1>
    
    <div id="chartdiv">
        Hold on, javascript is loading the plot ...
    </div>
    
    </body>
    </html>
    
    
    <script type="text/javascript">
    $(document).ready(function() {
    
        // we're combining the php array elements into a comma separated list
        // so that when the code is output javascript thinks it's an array.
        // if the $plot_row1 = array(1, 2, 3) then we'd get this:
        // 
        // row1 = [1, 2, 3];
        // 
        // if you needed quotes around the imploded php array values (if they
        // are strings where javascript is concerned) you could do this instead:
        // 
        // row1 = ["<?php echo substr(implode('","', $plot_row1), 0, -2); ?>"];
    
        row1 = [ <?php echo rtrim(implode(',', $plot_row1), ','); ?> ];
        row2 = [ <?php echo rtrim(implode(',', $plot_row2), ','); ?> ];
        row3 = [ <?php echo rtrim(implode(',', $plot_row3), ','); ?> ];
    
        // call your js function that creates the plot
        showBrittleness(row1,row2,row3);
    
        // add whatever js code you need to append the plot to $('#chartdiv')
    }
    </script>
    

    UPDATE

    According to a cursory examination of the jqplot docs, if you edit line 12 of the javascript you link from this:

    var plot1 = $.jqplot('chart1', [s1, s2], {
    

    To this:

    var plot1 = $.jqplot('chartdiv', [s1, s2], {
    

    Your function should render the plot in the ‘chartdiv’ id element. It seems the first argument to the $.jqplot function is the element in which to create it …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to learn about php's arrays today. I have a set of arrays like
In my quest in trying to learn more about OOP in PHP. I have
i have been trying to learn PHP Repeat Region... i have searched google but
I'm trying to learn PHP using NetBeans although I've come up against a problem
I've trying to learn PHP OOP and have made some research on how to
I have started to learn PHP. So installed WAMP server on my windows 7
I am trying to learn OOP in PHP, and I have some confusion about
I am trying to learn more about Javascript, I have been coding with PHP
I am trying to learn PHP with codeigniter, had have come across a problem.
I am trying to learn PHP classes so I can begin coding more OOP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.