3

I spent few days, but since I am completely new in JSON or PHP programming, can't solve my problem without your help.

Here is my problem - I have MySQL DB, I need to extract data from the table and build simple (for e.g. 2 columns) page (html or whatever) with table which consist info from my DB.

I wrote php connector, here it is:

 <?php

//require_once("data_connector.php"); //!connector
$dbtype = "MySQL";


$username = ''; // USERNAME
$password = ''; // PASSWORD
$hostname = ''; // HOSTNAME

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";

$selected = mysql_select_db("MASTER_TRACKER_DB",$dbhandle)
  or die("Could not select MASTER_TRACKER_DB");

/*
//execute the SQL query and return records
$result = mysql_query("SELECT SITE_ID, 3G_SITE_ID FROM MASTER_TRACKER WHERE SITE_ID LIKE '%ABK000%'");
//fetch tha data from the database
while ($row = mysql_fetch_array($result)) {
   echo "SITE_ID:".$row{'SITE_ID'}." 3G_SITE_ID:".$row{'3G_SITE_ID'}.
   "<br>";

}
*/

$data = new JSONDataConnector($dbhandle, $dbtype);

//$data->render_table("MASTER_TRACKER_DB.MASTER_TRACKER","SITE_ID","SITE_ID, 3G_SITE_ID");
$data->render_sql("SELECT SITE_ID, 3G_SITE_ID FROM MASTER_TRACKER_DB.MASTER_TRACKER WHERE SITE_ID LIKE '%ABK000%'", "", "SITE_ID, 3G_SITE_ID");

$data->dynamic_loading(30);

//close the connection
//mysql_close($dbhandle);

?>

From this script I see that I am able to connect to DB (I am getting Connected to MySQL message). Also, if I comment out PHP part which build table, I see that it can build table.

So, as next step, I would like to build table using JSON, so I will use it with Webix, so I made this page:

<!DOCTYPE html>
<html>
    <head>
 <title>Loading from DB</title>
    <link rel="stylesheet" href="codebase/webix.css" type="text/css"> 
    <script src="codebase/webix.js" type="text/javascript"></script> 

    </head>
    <body>
            <div class='header_comment'>Loading from DB (sqllite + php)</div>
            <div id="testA" style='height:600px'></div>
            <hr>

            <script type="text/javascript" charset="utf-8">

            webix.ready(function(){
                    grida = webix.ui({
                            container:"testA",
                            view:"datatable",
                            columns:[
                                    { id:"SITE_ID", header:"SIZE_ID",               width:200 },
                                    { id:"3G_SITE_ID",header:"3G_SITE_ID",          width:120 }
                            //      { id:"size",    header:"Size" ,                 width:80  },
                            //      { id:"architecture",    header:"PC",    width:60  }
                            ],
                            autowidth:true,
                            url: "data/data.php"
                    });     
            });


            </script>
    </body>
 </html>

But seems that I missed something since it shows empty table,

Can anyone please help me to make this page working?

Thanks to all in advance, Roman

Chris Forrence
  • 10,042
  • 11
  • 48
  • 64
Roman
  • 107
  • 6
  • 1
    Please dont use [the `mysql_` database extension](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), it is deprecated (gone for ever in PHP7) Specially if you are just learning PHP, spend your energies learning the `PDO` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) its really pretty easy – RiggsFolly Aug 22 '16 at 14:04
  • HINT: WHERE Clause: `WHERE col1 = 'val1' AND col2 = 'val2'` – RiggsFolly Aug 22 '16 at 14:06
  • check if your script really executes the call to the server. If it does - check what was the result from the server. – carmel Aug 22 '16 at 14:06
  • 1
    [Basic SQL tutorial](http://www.tutorialspoint.com/sql/) Save time start with a little bit of basic SQL syntax education – RiggsFolly Aug 22 '16 at 14:07
  • I suggest to use jQuery datatable. Take a look my related answer : http://stackoverflow.com/questions/39019420/how-to-get-first-column-of-jquery-datatable-as-checkbox/39020664#39020664 (ignore checkbox stuff there which you don't need). – Jitesh Sojitra Aug 22 '16 at 15:59
  • @RiggsFolly - thanks for the hints, I will read about PDO, but now thing is that I can connect to database, and if I comment out commented string - I will get output from database.The problem is rendering table from JSON. – Roman Aug 23 '16 at 05:02

0 Answers0