another question. When i try to run the my codes, my json array will end up in repeated loops. Is there any mistakes in my code or do i do it in another way?
<?php
//ini_set('memory_limit','2048M');
$servername = "localhost";
$username = "root";
$password = "imnoob";
$dbname = "csv_db";
$lala = "footfall";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (isset($_POST['tamp_mall'])) {
//$test = $_POST['tamp_mall'];
$result = mysqli_query($conn, "SELECT * FROM tampmall2012, tampmall2013, tampmall2014");
$data_points = array();
while ($row = mysqli_fetch_array($result)){
$point = array("x" => $row['weekid'], "y" => $row[$lala]);
array_push($data_points, $point);
}
echo json_encode($data_points, JSON_NUMERIC_CHECK);
mysqli_close($conn);
Yes, your sql query is wrong. You are doing cross join. There should be some condition to match the rows in the 3 tables. For example:
SELECT * FROM tampmall2012 t1, tampmall2013 t2, tampmall2014 t3
where t1.id = t2.id
and t2.id = t3.id
You can get more info on expected output from cross join here: http://www.w3resource.com/mysql/advance-query-in-mysql/mysql-cross-join.php
It will just give t1*t2*t3
number of rows where the data will be repeated unless some conditions are added.