2012-11-20 7 views
0

DB에서 최대 값을 가져 오는 텍스트 상자가 있습니다. 그러나 그것은 잘못된 가치를 제공합니다.올바른 값을 제공하지 않는 MYSQL/PHP 쿼리

여기에 무엇이 잘못되었는지 알아낼 수 있습니까?

basicInformation 기능 :

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; 
} 

내 inputBookingRef 기능 :

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; 
} 

이 라인에서 :

echo print_r($values, true); 

마지막 최대 값을 표시합니다. 하지만 제 텍스트 상자에서는 가치 번호 1을 부여하고 있습니다. 코딩에 어떤 문제가 있는지 알지 못합니다. 어떤 도움이라도 대단히 감사 드리며 프로그램을 계속 진행할 수 있습니다. 감사.

답변

0

때마다 당신은 당신에게 결과의 다음 값을 줄 것이다

mysql_fetch_assoc($query) 

를 호출합니다. 쿼리의 행이 하나뿐입니다 (실제 행 인 경우). 행 값이 $ 값 에 할당되고 WHILE 루프가 전혀 실행되지 않아야합니다.

휴가에만 문 중 하나 괜찮을한다) 주석 이후

편집 : 도

$ 값이 아마 인 inputBookingRef() 방법 $values++;의 목적은 무엇인가 문자열 형식의 .. ++ 뭔가 재미있을 것입니다.

+0

안녕하세요. 내 while 회 돌이를 주석 처리했습니다. 나는이 모든 것을 다시 시도했지만 텍스트 상자는 나에게 1의 값을 준다. –

+0

예, 얼마 전에 inputBookingRef 함수에서 $ values ​​++를 삭제 했었지만, 그랬을 때, 텍스트 상자에는 값이 없다. –

관련 문제