MYSQL/PHP查询未给出正确的值
我有一个文本框,它从DB中提取最大值。但它给出了错误的值 你能帮我找出哪里出了问题吗 基本信息功能:MYSQL/PHP查询未给出正确的值,php,mysql,Php,Mysql,我有一个文本框,它从DB中提取最大值。但它给出了错误的值 你能帮我找出哪里出了问题吗 基本信息功能: private function basicInformation() { // initialize variables $host = "localhost"; $db_name = "test"; $tbl_name = "ballpark_details"; $username = "root"; $password = "
private function basicInformation() {
// initialize variables
$host = "localhost";
$db_name = "test";
$tbl_name = "ballpark_details";
$username = "root";
$password = "";
// connect to database
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB"); # ORDER BY ballpark_details_id DESC
$query = mysql_query("SELECT MAX(ballpark_details_booking_ref) as max_booking_ref FROM `ballpark_details`");
//Getting the max ref_id
$values = mysql_fetch_assoc($query);
while ($query !=-1 && $row = mysql_fetch_assoc($query)) {
$max = $row['max_booking_ref'];
}
echo print_r($values, true);
$html = "";
$html .= '<fieldset id="basic-information" class="ui-widget">' . PHP_EOL;
$html .= '<legend>Basic Ballpark Information</legend>' . PHP_EOL;
$rowClass = "input-row";
//$html .= $this->wrapLabelTextbox($this->inputBookingRef($values['max_booking_ref)']), $rowClass);
$html .= $this->wrapLabelTextbox($this->inputBookingRef($max), $rowClass);
//$html .= $this->wrapLabelTextbox($this->inputBookingRef(), $rowClass);
$html .= $this->wrapLabelTextbox($this->inputBank(), $rowClass);
$html .= $this->wrapLabelTextbox($this->inputRegion(), $rowClass);
$html .= $this->wrapLabelTextbox($this->inputDescription(), $rowClass);
$html .= $this->wrapLabelTextbox($this->inputNotes(), $rowClass);
$html .= $this->wrapLabelTextbox($this->inputStartDate(), $rowClass);
$html .= $this->wrapLabelTextbox($this->inputRequestedDeliveryDate(), $rowClass); #$this->inputEndDate()
$html .= $this->wrapLabelTextbox($this->inputExpiryDate(), $rowClass);
$html .= $this->wrapLabelTextbox($this->inputURL(), $rowClass);
$html .= $this->wrapLabelTextbox($this->inputCAR(), $rowClass);
(strcmp($_GET["page"], "createballpark"))?
$html .= $this->wrapLabelTextbox($this->inputProjectStatusEdit(), $rowClass) :
$html .= $this->wrapLabelTextbox($this->inputProjectStatusCreate(), $rowClass);
$html .= '</fieldset>';
return $html;
}
private function inputBookingRef($values){
//$values = $this->bookingRef;
$html = "";
$values++;
$html .= '<label for="ref">Booking Ref: </label>';
$html .= HTML::inputText("ref", 20, $values) . PHP_EOL;
return $html;
}
它正在显示最后一个最大值。但在我的文本框中,它只是给出了数值1。我不知道我的密码有什么问题。非常感谢您的帮助,我可以继续我的计划。谢谢。每次你打电话来
mysql_fetch_assoc($query)
它将为您提供结果的下一个值。
查询中只有一行(如果这是真实的)。
行值被指定给$values
您的WHILE循环根本不应该执行
只留下一条语句,就可以了;)
评论后编辑:
还有什么目的
$values++在inputBookingRef()方法中编码>
$values可能是字符串类型..++将使它变得有趣。Hi注释了我的while循环。我已经尝试了一遍,但是文本框仍然给了我数值1。是的,我在不久前删除了inputBookingRef函数中的$values++,但是当我删除时,文本框中没有数值
mysql_fetch_assoc($query)