我有一個動態的MySQL表,有20列和1行,其中id = 1。新數據將作爲第二行添加到表中,其中id = 2,所以。我需要用PHP讀取最新的數據行(總是最後一個id)。用php從MySQL讀取數據
我有一個代碼不適合我的數據庫。我應該如何改變它?
$link = mysqli_connect($mysql_host,$mysql_user,$mysql_password,$mysql_dbname,$mysql_port) or die("Error " . mysqli_error($link));
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// $d.= 'Connected successfully';
$sql = "SELECT id, AbW_L FROM abwasser order by id desc limit 1 ";
$result= $link->query($sql);
mysqli_query($link,"select * from tbl");
$i=0;
$d="{";
while ($row = mysqli_fetch_row($result)) {
switch($i)
{
case 0:
$d.= '"outtemp":'. $row[2].",";
break;
case 1:
$d.= '"intemp":'. $row[2].",";
break;
case 2:
$d.= '"tanktemp":'. $row[2].",";
break;
case 3:
$d.= '"fillevel":'. $row[2];
break;
default:
break;
}
$i++;
}
$d.="}";
mysqli_close($link);
echo $d;
問候
'我有一個不適合我的數據庫的代碼。「爲什麼? – 2015-02-05 13:14:04
因爲我的SQL有20列,這意味着$行[x]中的x應該從1更改爲20,但在此代碼中,我可以只有$ row [2] otherweis我得到一個錯誤。這個代碼的數據庫有另一個結構:( – 2015-02-05 13:20:56
@point_system我認爲你被問到你爲什麼沒有寫你自己的代碼,或者閱讀大概出現的教程來修復它以達到你的目的 – 2015-02-05 13:36:01