Commit 9f5eba40 authored by sam.markey's avatar sam.markey

Fetching data script

parent 99b36dd7
<?php
if (isset($_GET['table'])) {
$table = trim(htmlspecialchars($_GET['table']));
if(strcmp($table,'museum') == 0 || strcmp($table,'item_museum') == 0){
$language = $_GET['language'];
getTable($table,$language);
}else{
getTable($table,"");
}
}
else{
echo 'check_isset';
}
function getTable($tablename,$languageType)
{
require_once 'connect_db.php';
$stmt = mysqli_stmt_init($connect);
if(strcmp($tablename,'museum') == 0 || strcmp($tablename,'item_museum') == 0){
$sql = 'SELECT * FROM ' . $tablename ." WHERE language='".$languageType."';";
} else{
$sql = 'SELECT * FROM ' . $tablename . ";";
}
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "ERROR: ".$sql;
} else {
mysqli_stmt_execute($stmt);
$dataArray = array();
if ($resultData = mysqli_stmt_get_result($stmt)) {
while ($row = mysqli_fetch_assoc($resultData)) {
$rows[] = $row;
}
echo json_encode(JsonVerify($rows));
}
}
mysqli_stmt_close($stmt);
}
function JsonVerify($var)
{
if (is_array($var)) {
foreach ($var as $key => $value) {
$var[$key] = JsonVerify($value);
}
} elseif (is_string($var)) {
return mb_convert_encoding($var, "UTF-8", "UTF-8");
}
return $var;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment