简体   繁体   中英

How to get SQL data via PHP into D3 matrix

I've been looking for this answer a few weeks now and no succes.

In D3 to build a simple graph I might use a matrix like:

<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js">
</script>

<script>
   var matrix = [
          [1000, 10000, 0, 0, 1000, 3000, 4000, 0, 4000,1000, 2000],
          [2000, 2000, 2000, 0, 0, 4000, 1000, 4000, 4000,1000, 2000],
          [1000, 2000, 0, 0, 3000, 0, 1000, 4000, 4000,1000, 2000],
          [1000, 2000, 4000, 0, 3000, 4000, 1000, 4000, 4000,1000, 2000],
          [1000, 2000, 4000, 0, 0, 4000, 1000, 4000, 4000,1000, 2000],
          [10000, 0, 0, 0, 7000, 2000, 1000, 4000, 4000,1000, 2000],
          [1000, 2000, 3000, 4000, 3000, 4000, 1000, 4000, 4000,1000, 2000],
          [0, 2000, 3000, 4000, 3000, 4000, 1000, 4000, 4000,1000, 2000],
          [1000, 2000, 3000, 4000, 3000, 4000, 1000, 4000, 4000,1000, 2000],
          [1000, 1000, 1000, 3000, 4000, 7000, 1000, 4000, 4000,1000, 2000],
          [1000, 1000, 1000, 7000, 3000, 4000, 1000, 4000, 4000,1000, 2000]
       ];
</script>

What I'm looking for is to have these numbers coming from my SQL query, like:

$result = mysql_query("SELECT Item-1, 
                              Item-2, 
                              Item-3, 
                              .... 
                         FROM $tbl_name 
                         WHERE Organization = 'SBM Offshore N.V.'");

I would appreciate any help or direction towards an answer.

Many thanks.

Data is coming from a simple MySQL database. It will be called like:

<?php

$host = "....";
$LoginNaam = "....";
$Password = "....";
$db_name = "....";
$tbl_name = "....";

$con = mysql_connect($host, $LoginNaam, $Password);
if (!$con)
  {
  die(mysql_error("can't connect"));
  }
mysql_select_db($db_name, $con) or die(mysql_error("can't find database"));

$result = mysql_query(" SELECT Meldingsplichtige, Aantal_aandelen, Kapitaalbelang, Stemrecht FROM $tbl_name WHERE Uitgevende_instelling = 'SBM Offshore N.V.' ");

?>

It is one tabel with a few columns and rows. Each row might hold a type VARCHAR or INT.

When it is the INT type it need to be used to draw a line or graph. For the type VARCHAR I would use it as a text element.

Just for testing purposes, I could build a Database with one column and only integers.

Thanks for the help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM