Så er det lykkes at få mere info. Jeg har også fået et script hvor jeg kan hente data. Men da det er en PG database. og mine begrænsede evner var i Mysql får jeg det ikke helt til.
Måske i kan vise mig vejen til info eller hjælpe på anden måde
Jeg sak bruge "sum" til at kunne sætte ind på en sige når den loader, uden form og submit,
Før brugte jeg noget i denne stil:
$member_sql = mysql_query("SELECT * FROM members WHERE member_id='$member_id'")
or die(mysql_error());
$member_row = mysql_fetch_array( $member_sql );
$firstname = $member_row['firstname'];
Men får ikke rigtig det til med det "nye".
(isset($_GET['action']))?$action=$_GET['action']:$action=NULL;
(isset($_POST['select']))?$select=$_POST['select']:$select=NULL;
(isset($_POST['from']))?$from=$_POST['from']:$from=NULL;
(isset($_POST['where']))?$where=$_POST['where']:$where=NULL;
(isset($_POST['order_by']))?$order_by=$_POST['order_by']:$order_by=NULL;
(isset($_POST['limit']))?$limit=$_POST['limit']:$limit=NULL;
(isset($_POST['update']))?$update=$_POST['update']:$update=NULL;
(isset($_POST['set']))?$set=$_POST['set']:$set=NULL;
(isset($_POST['insert']))?$insert=$_POST['insert']:$insert=NULL;
(isset($_POST['fields']))?$fields=$_POST['fields']:$fields=NULL;
(isset($_POST['values']))?$values=$_POST['values']:$values=NULL;
if (isset($_GET['select'])) $select=$_GET['select'];
if (isset($_GET['from'])) $from=$_GET['from'];
if (isset($_GET['where'])) $where=$_GET['where'];
if (isset($_GET['order_by'])) $order_by=$_GET['order_by'];
if (isset($_GET['update'])) $update=$_GET['update'];
if (isset($_GET['set'])) $set=$_GET['set'];
if (isset($_GET['insert'])) $insert=$_GET['insert'];
if (isset($_GET['fields'])) $fields=$_GET['fields'];
if (isset($_GET['values'])) $values=$_GET['values'];
$serverurl="
https://xxx.xxxx.dk/xx/api";$user = 'user';
$db='xDBx';
$api_key='XXXXXXXXZZZZ';
if ($action) {
if ($action == 'fetch_from_table') fetch_from_table($serverurl,$db,$user,$api_key,$select,$from,$where,$order_by,$limit);
elseif ($action == 'update_table') update_table($serverurl,$db,$user,$api_key,$update,$set,$where);
elseif ($action == 'insert_into_table') insert_into_table($serverurl,$user,$db,$api_key,$insert,$fields,$values);
} else {
print "<form name=\"rest_api_client\" action=\"rest_api_client.php?action=fetch_from_table\" method='post'>\n";
print "<table><tbody>";
print "<tr><td>Select</td><td><input style=\"width:1000px;\" type='text' name='select' value=\"$select\"></td></tr>\n";
print "<tr><td>From</td><td><input style=\"width:1000px;\" type='text' name='from' value=\"$from\"></td></tr>";
print "<tr><td>Where</td><td><input style=\"width:1000px;\" type='text' name='where' value=\"$where\"></td></tr>";
print "<tr><td>Order by</td><td><input style=\"width:1000px;\" type='text' name='order_by' value=\"$order_by\"></td></tr>";
print "<tr><td>Limit</td><td><input style=\"width:1000px;\" type='text' name='limit' value=\"$limit\"></td></tr>";
print "<tr><td colspan='2' align='center'><input type='submit' name='go' value='Go'></td></tr>\n";
print "</tbody></table>";
print "</form>";
print "<form name=\"rest_api_client\" action=\"rest_api_client.php?action=update_table\" method='post'>\n";
print "<table><tbody>";
print "<tr><td>Update</td><td><input style=\"width:1000px;\" type='text' name='update' value=\"$update\"></td></tr>\n";
print "<tr><td>Set</td><td><input style=\"width:1000px;\" type='text' name='set' value=\"$set\"></td></tr>";
print "<tr><td>Where</td><td><input style=\"width:1000px;\" type='text' name='where' value=\"$where\"></td></tr>";
print "<tr><td colspan='2' align='center'><input type='submit' name='go' value='Go'></td></tr>\n";
print "</tbody></table>";
print "</form>";
print "<form name=\"rest_api_client\" action=\"rest_api_client.php?action=insert_into_table\" method='post'>\n";
print "<table><tbody>";
print "<tr><td>Insert into</td><td><input style=\"width:1000px;\" type='text' name='insert' value=\"$insert\"></td></tr>\n";
print "<tr><td>Fields</td><td><input style=\"width:1000px;\" type='text' name='fields' value=\"$fields\"></td></tr>";
print "<tr><td>Values</td><td><input style=\"width:1000px;\" type='text' name='values' value=\"$values\"></td></tr>";
print "<tr><td colspan='2' align='center'><input type='submit' name='go' value='Go'></td></tr>\n";
print "</tbody></table>";
print "</form>";
}
function fetch_from_table($serverurl,$db,$user,$api_key,$select,$from,$where,$order_by,$limit) {
$result = file_get_contents($serverurl."/rest_api_client.php?action=fetch_from_table&user=$user&db=$db&key=$api_key&select=".urlencode($select)."&from=".urlencode($from)."&where=".urlencode($where)."&order_by=".urlencode($order_by)."&limit=".urlencode($limit));
$result = json_decode($result, true);
if (!is_array($result)) {
print "error: ".$result;
} else {
print "<table border='1'><tbody>";
$rows=count($result);
$cols=count($result[0]);
for ($x=0;$x<$rows;$x++){
print "<tr>";
for ($y=0;$y<$cols;$y++) {
print "<td>".$result[$x][$y]."</td>";
}
print "</tr>";
}
print "</tbody></table>";
}
print "<a href=\"rest_api_client.php?select=$select&from=$from&where=$where&order_by=$order_by&limit=$limit\">Return to query page</a>";
}
function update_table($serverurl,$db,$user,$api_key,$update,$set,$where) {
$result = file_get_contents($serverurl."/rest_api_client.php?action=update_table&db=$db&user=$user&key=$api_key&update=".urlencode($update)."&set=".urlencode($set)."&where=".urlencode($where));
$result = json_decode($result, true);
if (!is_numeric($result)) {
print "error: ".$result;
} else {
print "<table border='1'><tbody>";
print "<td>".$result."</td>";
print "</tr>";
print "</tbody></table>";
}
print "<br><a href=\"rest_api_client.php?update=$update&set=$set&where=$where\">Return to query page</a>";
}
function insert_into_table($serverurl,$db,$user,$api_key,$insert,$fields,$values) {
$result = file_get_contents($serverurl."/rest_api_client.php?action=insert_into_table&user=$user&db=$db&key=$api_key&insert=".urlencode($insert)."&fields=".urlencode($fields)."&values=".urlencode($values));
$result = json_decode($result, true);
if (!is_numeric($result)) {
print "error: ".$result;
} else {
print "<table border='1'><tbody>";
print "<td>".$result."</td>";
print "</tr>";
print "</tbody></table>";
}
print "<br><a href=\"rest_api.php?insert=$insert&fields=$fields&values=$values\">Return to query page</a>";
}