2014-02-11 30 views
-1

我想创建一个网页,我必须展示一个特定ID的记录,但它显示我此错误
我想抓取多行,在抓取行中有错误?

Notice: Undefined variable: mysqli in line 82.

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

这是程序的PHP代码。

$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

$ CON = mysqli_connect( “XXXX”, “XXXX”, “XXXX”, “XXXX”);如果(mysqli_connect_errno()){ 回声 “无法连接到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); echo“”; echo“”; echo“name”; echo“address”; echo“phone”; echo“uan”; echo“location”; echo“” ; 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

哇。它是快速的 –