Skip to content

Instantly share code, notes, and snippets.

@basicssm
Created May 19, 2015 07:39
Show Gist options
  • Save basicssm/39872cad418ddc7300c4 to your computer and use it in GitHub Desktop.
Save basicssm/39872cad418ddc7300c4 to your computer and use it in GitHub Desktop.
<?php
require_once(__DIR__.'/../lib/settings.php');
require_once(__DIR__.'/../lib/conexion.php');
if(isset($_POST['table'])){
$table = $_POST['table'];
$query = "select * from ".$table." order by orden asc;";
if ($result = $mysqli->query($query)){
$info_campo = $result->fetch_fields();
$data = array();
while($object = $result->fetch_object())
{
$dataItem = new stdClass();
foreach($info_campo as $info)
{
$col = $info->name;
$dataItem->$col = utf8_encode($object->$col);
}
$data[] = $dataItem;
}
$result = new stdClass();
$result->ok = 'true';
$result->data = $data;
echo json_encode($result);
}
else
{
$result = new stdClass();
$result->ok = 'false';
$result->data = 'Database error';
echo json_encode($result);
}
}
else{
$result = new stdClass();
$result->ok = 'false';
$result->data = 'Error';
echo json_encode($result);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment