-1
我有這個查詢,我用它來更新表。 的問題是,我只需要更新值從「未定義」只更新非空記錄
隨着有人在這裏的幫助我得到這個查詢不同:
$sqlStart="UPDATE forma SET ";
$sql="";
if (!empty($postDyqani_pergjegjes)) $sql += " dyqani_pergjegjes='$postDyqani_pergjegjes',";
if (!empty($postEmri)) $sql += " emri='$postEmri',";
if (!empty($postKlienti)) $sql += " klienti='$postKlienti',";
if (!empty($postTelefoni)) $sql += " telefoni='$postTelefoni,'";
if (!empty($postMontim)) $sql += " montim='$postMontim',";
if (!empty($postAdresa)) $sql += " adresa='$postAdresa',";
if (!empty($postData_e_shitjes)) $sql += " data_e_shitjes='$postData_e_shitjes',";
if (!empty($postDifekti)) $sql += " difekti='$postDifekti',";
if (!empty($postTekniku_emer)) $sql += " tekniku_emer='$postTekniku_emer',";
if (!empty($postTekniku_mesazh)) $sql += " tekniku_mesazh='$postTekniku_mesazh',";
if (!empty($postData_fillim)) $sql += " data_fillim='$postData_fillim',";
if (!empty($postData_mbarim)) $sql += " data_mbarim='$postData_mbarim',";
if (!empty($postData)) $sql += " data='$postData',";
if (!empty($postStatus)) $sql += " status='$postStatus',";
// replace the last `,` for `;`
if ($sql != "") {
$sql = substr($sql, 0, -1) . ";";
// replace the last `,` for `;`
// run sql command
echo $sqlCommand = $sqlStart.$sql;
$result=mysql_query($sqlCommand) or die(mysql_error()) ;
} else {
}
它雖然不會執行.. 請給我一手在這.. 如果我打印的變量其中大部分結果是undefined
謝謝
change + = to。= – Kao
「undefined」?在PHP或MySQL中沒有這種價值。請描述你想要做的更好。也許'......在哪裏不是NULL'? – deceze
的想法是,更新查詢將flexible,所以一些變量,即使他們在查詢中,可能沒有一個值,當我打印它們時,它說undefined –