最近我正在學習單頁面應用程序,但我遇到了一個問題,我正在處理的項目是在一個包含多個文件夾的文件夾內,php js文件夾在主文件夾,並且每個文件都包含其類型的文件,問題在於其中一個名爲getmax.php
的php文件給了我最大的id,我想在一個名爲module.js
的js文件中使用這個max(id)
,以便爲新模塊指定下一個id,即module.js
應該給這個id到另一個名爲insert.php
的php文件,如果我手動設置ID,module.js
和insert.php
之間的連接可以正常工作。但我無法弄清楚如何使用getmax.php
文件中的max(id)
。使用phpfile輸出內部js文件文件作爲變量
注意:我最近注意到我在使用MySQL,我應該使用mysqli
我稍後會修復它。
的getmax.php
是:
<?php
// alle relevanten Tabellen abfragen und als json zurückgeben.
$json["status"] = "running";
$details[] = "started get_tables ";
// Include confi.php
include_once('confi.php');
//var_dump($_POST);
$request_body = file_get_contents('php://input');
// first store the given set of data to keep it for future analysis
$statement = "INSERT INTO tbl_archive (content) VALUES ('$request_body');";
mysql_query($statement);
$input = json_decode($request_body, true);
// now check if valid user
$user = $input["user"];
$username = $user["username"];
$password = $user["password"];
if($password and $username){
$mySQLstring = "SELECT username, password, id, create_user FROM tbl_user where username = '$username' ;";
$json["statement"][] = $mySQLstring;
$qur = mysql_query($mySQLstring);
//var_dump ($qur);
if ($qur){
$max = mysql_fetch_assoc($qur);
}
if ($max){
$json["max"] = $max;
if ($max["password"] == $password){
$json["username"] = $username;
$json["id"] = $max["id"];
$json["create_user"] = $max["create_user"];
$json["status"] = "ok";
$tables = array("class", "class_user", "module", "module_class", "module_user", "rating", "student", "student_class");
//$tables = array("class");
foreach($tables as $table){
if ($table == 'module'){
$statement ='SELECT create_user, MAX(id) FROM tbl_'.$table;
//$statement .= ' GROUP BY create_user' ;
$statement .= ' WHERE create_user = 19 ' ;
$qur = mysql_query($statement);
if ($qur){
while($r = mysql_fetch_array($qur, MYSQL_ASSOC)){
//var_dump($r);
//echo (json_encode($r));
$result[$table][] = $r;
}
}
}
}
$json = array("status" => "ok", "data" => $result);
}
}
}
@mysql_close($conn);
/* Output header */
header('Content-type: application/json');
echo json_encode($json);
?>
要從php到javascript的價值,你可以使用AJAX。 –