我正在尝试更新我需要显示MySql错误字段的代码。该脚本检查MySql,如果结果== 0基于传递3个变量,那么$ outstring将在$ outstring中发送错误。这个$ outstring由jQuery使用data.opp来处理,以确定错误或成功,并在对话框窗口中显示结果。发生的事情是我的所有字段都显示在$ outstring中,我只想显示哪个字段失败。
最好的方法是什么,所以我知道哪个$变量产生0结果并显示MySql的哪个部分失败。我已经发布了处理此输出的相关代码部分。非常感谢。
<?php
$outString = ''; // NEED to do HTML output Formating on SERVER Side
// Only Return a String to browser NOT an array
foreach ($array as $box) {
$box = mysql_real_escape_string($box);
$sql = "SELECT custref,customer,department,status FROM boxes WHERE custref = '$box' ";
$sql .= "AND customer = '$company' ";
$sql .= "AND department = '$dept' ";
$sql .= "AND status = '1' ";
$result = mysql_query($sql) or die ('{"opp":"error","box":"' . mysql_error() . '"}');
// If there are no entries, send output to outstring as error
if (mysql_num_rows($result) == 0) {
$outString .= $box . ' ';
$outString .= $dept . ' ';
$outString .= '1' . ' ';
} // foreach ($array
}
if ($outString) { // if there are numbers in this string, then there are error Duplicates
$error = array('opp' => "error", 'box' => $outString); // box will have the TEXT for the Dialog Text
// IMPORTANT, have changed JSON output to use an Opperation (opp) to indicate
// in javascript if there was an error OR not
$output = json_encode($error);
echo $output;
exit();
}
?>