I'm developing a web service with one parameter which is the name of a table. Is there any method to determine all the attributes of my table while fetching the request.
<?php
// Call Address URL: url: http://localhost/test1/new.php?tab=Request_Table -> GET
$response = array(); //array for JSON response
if(isset($_GET["tab"])){ //check for post data
$tab = $_GET['tab'];
$element = array();
if(!empty($tab)){
$result = mysql_query("SELECT * FROM '$tab'");
if(!empty($result)) { //check for empty result
while($data = mysql_fetch_array($result)){ // Fetching results
extract($data);
$element["attribute1"] = $data["attribute1"];
$element["attribute2"] = $data["attribute2"];
}
$response = array("success" => 1, "element" => $element);
echo json_encode($response); // echoing JSON response
}else{ //not element found
$response["success"] = 0;
$response["message"] = "No element found";
echo json_encode($response);
}
}else { //not element found
$response["success"] = 0;
$response["message"] = "No element found";
echo json_encode($response);
}
}else{ // required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
}
?>