0

I am using jqplot to show data in a graph.I am able to fetch data in the array ,but I have a small problem to plot data the format is

[["Pens",10],["Pencils",30],["Erasers",40],["Charts",3]]

I am getting data in the following format

[["Pens"],["10"],["Pencils"],["30"],["Erasers"],["40"],["Charts"],["3"]]

my code is as follows

PHP Code

$dbname = 'dbname';
$username = 'root';
$password = 'password1!';
try {
    /* Establish the database connection */
    $conn = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $result = $conn->query("SELECT Compliancestatus,value FROM COUNT_VALUE WHERE Zone='PZ' and country='AU' and `Compliancestatus` is not null");
    $jsonTable = json_encode($rows);
    print_r($jsonTable);
} catch (PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}
//mysql_close($conn);
$conn = null;
$rows = array();
foreach ($result as $r) {
    $rows[] = array($r['Compliancestatus']);
// Values of each slice
    $rows[] = array($r['value']);
}

please help me in this regard.

1 Answer 1

1

Change this

$rows[] = array($r['Compliancestatus']);
// Values of each slice
$rows[] = array($r['value']);

To

$rows[] = array($r['Compliancestatus'],(int)$r['value']);
Sign up to request clarification or add additional context in comments.

1 Comment

hi Joni it is working but value is coming as a string but i need it in the integer form i,e ["Compliance",50] this way but it is coming like this ["Compliance","50"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.