2014-02-11 3 views
-1

나는 내가 특정 ID의 기록을 보여주기 위해이 페이지를 만들려하지만 나에게이 프로그램의 PHP 코드이 오류
여러 행을 가져 오려고하는데 행을 가져 오는 중에 오류가 있습니까?

Notice: Undefined variable: mysqli in line 82.

Fatal error: Call to a member function query() on a non-object in line 82.

을 보이고있다. = mysqli_connect

$con=mysqli_connect("XXXX","XXXX","XXXX","XXXX"); 
if (mysqli_connect_errno()) 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 

$id = $_GET['id']; 
$sql = "SELECT * FROM details WHERE cat_id = $id"; 
$result = mysqli_query($con,$sql); //line #82 
$row = mysqli_fetch_array($result); 

while($row = mysqli_fetch_array($result)){ 
    $id = $row['cat_id']; 
    echo "<tr>"; 
    echo "<td><a href='detail.php?id=$id' >" . $row['cat_name'] . "</a></td>"; 
    echo "</tr>"; 
} 
echo "<table>"; 

echo "<tr>"; 
echo  "<th>name</th>"; 
echo  "<th>address</th>"; 
echo  "<th>phone</th>"; 
echo  "<th>uan</th>"; 
echo  "<th>location</th>"; 
echo "</tr>"; 

mysqli_close($con); 
+1

당신은 라인 (82)을 표시 할 수 있습니다? –

+0

";}"이라고 가정합니다. ... – user1844933

+0

코드에서 멤버 함수'query'에 대한 호출이 없습니다. – Barmar

답변

-3

$ 콘 ("XXXX", "XXXX", "XXXX", "XXXX"); 경우 (mysqli_connect_errno()) {에코 "의 MySQL에 연결하지 못했습니다". mysqli_connect_error();} $ id = $ _ GET [ 'id']; $ sql = "SELECT * 상세 정보 WHERE cat_id = $ id"; $ result = mysqli_query ($ con, $ sql); "전화", "에코", 에코 "위치", 에코 ""에코 "이름"; 에코 "이름"; ; while ($ row = mysqli_fetch_array ($ result)) {$ id = $ row [ 'cat_id']; echo ""; 에코 "". $ row [ 'cat_name']. ""; 에코 ""; } mysqli_close ($ con);

+1

왜 코드를 더 이상 쓸모없는 mysql 확장으로 다운 그레이드 했습니까? – Barmar

-1

당신은 다음과 같이 정확하게 기록을 통해 루프 수 없습니다 :

$id = $_GET['id']; 
$result = mysqli_query($con,"SELECT * FROM details WHERE cat_id = $id"); 
echo "<table> 
<tr> 
<th>name</th> 
<th>address</th> 
<th>phone</th> 
<th>uan</th> 
</tr>"; 
while($row = mysqli_fetch_array($result)){ 
    echo "<tr>"; 
    echo "<td>" . $row['name'] . "</td>"; 
     echo "<td>" . $row['address'] . "</td>"; 
     echo "<td>" . $row['phone'] . "</td>"; 
     echo "<td>" . $row['uan'] . "</td>"; 
    echo "</tr>"; 
} 
+0

와우. 그것은 빨랐다. –

관련 문제