2013-12-21 45 views
-2

我只是想,讓我查看我的數據庫...... 行列表中選擇一個表,但我的代碼將無法正常工作, 這裏是我的全部代碼:如何通過表查看數據庫上的行?

$con=mysqli_connect("fd***.biz.nf","1549087_admin","*****","******"); 
$sql = "SELECT * FROM Solo;"; 
$myData = mysqli_query($con,$sql); 

echo "<table border='1'> 
<tr> 
<th>Grade/Yr. Level</th> 
<th>First Name</th> 
<th>Middle Name</th> 
<th>Last Name</th> 
<th>Age</th> 
<th>Position</th> 
<th>Motto</th> 
</tr>"; 

while($row = mysqli_fetch_array($myData, MYSQLI_ASSOC)) 
{ 
echo "<tr><td>"; 
echo $row['gradeyrlevel']; 
echo "</tr><td>"; 
echo $row['firstname']; 
echo "</tr><td>"; 
echo $row['middlename']; 
echo "</tr><td>"; 
echo $row['lastname']; 
echo "</tr><td>"; 
echo $row['age']; 
echo "</tr><td>"; 
echo $row['position']; 
echo "</tr><td>"; 
echo $row['motto']; 
echo "</tr><td>"; 
echo "</tr>"; 
} 
echo "</table>"; 
mysqli_close($con); 

請幫助我。

的錯誤是:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /srv/disk10/1549087/www/rooseveltcollegecainta.co.nf/admin/adminpage/index.php on line 125

線125

while($row = mysqli_fetch_array($myData, MYSQLI_ASSOC)) 
+0

這是什麼意思「不工作」?你檢索哪個錯誤? –

+0

更多細節將是有益的。什麼不工作? –

+0

這是錯誤出現了: 警告:mysqli_fetch_array()預計參數1被mysqli_result,在給定的/srv/disk10/1549087/www/rooseveltcollegecainta.co.nf/admin/adminpage/index.php在線路125 – user3026685

回答

0

同時使用的mysqli你需要通過連接可變嘗試使用

**$result=mysqli_query($con,$query);** 

,而不是$result=mysqli_query($query); 希望這作品

+0

它不工作:( – user3026685

0

試試這個:

$mysqli = new mysqli(HOST,USER,PASS,DATABASE); 
if (mysqli_connect_errno()) { 
    printf("Connect failed: %s\n", mysqli_connect_error()); 
    exit(); 
} 
$query = "SELECT * FROM Solo"; 
$result = $mysqli->query($query); 
while($row = $result->fetch_array(MYSQLI_ASSOC)) 
{ 
    echo "<tr>"; 
    echo "<td>" . $row['gradeyrlevel'] . "</td>"; 
    echo "<td>" . $row['firstname'] . "</td>"; 
    echo "<td>" . $row['middlename'] . "</td>"; 
    echo "<td>" . $row['lastname'] . "</td>"; 
    echo "<td>" . $row['age'] . "</td>"; 
    echo "<td>" . $row['position'] . "</td>"; 
echo "<td>" . $row['motto'] . "</td>"; 
echo "</tr>"; 
} 
+0

這個錯誤出現了: 致命錯誤:調用一個成員函數fetch_array()非對象 – user3026685

0
try this............ 
    $con=mysql_connect("host","username","password"); 
    mysql_select_db('dbname'); 
    $query="SELECT * FROM SOLO"; 
    $result=mysql_query($query); 

    while($data = mysql_fetch_row($result)) 
    { 
     . 
     . 
     . 
     . 
     . 

    } 
+0

這種類型的錯誤出現在: 警告:和mysql_fetch_row()預計參數1是資源,布爾在 – user3026685

0

的錯誤意味着變量$ result設置爲false,而不是查詢的結果。檢查您提供的表名是否正確,以及您用來登錄的數據庫用戶是否有權訪問它。

+0

給出它是正確的。:( – user3026685

0

你已經把mysqli的查詢中一個分號,所以你發現這個error.you必須使用下面的代碼

$result = mysqli_query($con,"SELECT * FROM Solo"); 
+0

出現同樣的錯誤:( – user3026685

0

As per your other question here , you obviously have your table name wrong (word/letter-case).

在這種問題,你說我引用自:「IT工作!謝謝你了!:)」

(LINK to comment)

兩個可能的錯誤。

1)拼錯表名。 SOLO而不是Solo(這很可能是這種情況)。

2)額外分號=>$sql = "SELECT * FROM Solo;";
替換=>$sql = "SELECT * FROM Solo";

如果不工作,然後仔細檢查所有的字母的大小寫,如:

  • 表名
  • 列名
  • 包括你的數據庫連接
  • 確保列存在並正確
  • 命名檢查一切

注::Solo一樣SOLOsolo


現在試試這個,但閱讀腳註下面,因爲它們包含將被證明是你的學習有利於一些重要信息SQL和PHP。

$con=mysqli_connect("fd***.biz.nf","1549087_admin","*****","******"); 

// Check connection 
if (mysqli_connect_errno($con)) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

$sql = "SELECT * FROM `SOLO`"; // added backticks around SOLO table name 

if($sql === FALSE) { 
die(mysqli_error()); // TODO: better error handling 
} 

$myData = mysqli_query($con,$sql); 

echo "<table border='1'> 
<tr> 
<th>Grade/Yr. Level</th> 
<th>First Name</th> 
<th>Middle Name</th> 
<th>Last Name</th> 
<th>Age</th> 
<th>Position</th> 
<th>Motto</th> 
</tr>"; 

while($row = mysqli_fetch_array($myData, MYSQLI_ASSOC)) 
{ 
echo "<tr><td>"; 
echo $row['gradeyrlevel']; 
echo "</tr><td>"; 
echo $row['firstname']; 
echo "</tr><td>"; 
echo $row['middlename']; 
echo "</tr><td>"; 
echo $row['lastname']; 
echo "</tr><td>"; 
echo $row['age']; 
echo "</tr><td>"; 
echo $row['position']; 
echo "</tr><td>"; 
echo $row['motto']; 
echo "</tr><td>"; 
echo "</tr>"; 
} 
echo "</table>"; 
mysqli_close($con); 

Footnotes:

建議教程:(雖然有可以在網上找到許多其他的)

當然還有,在PHP和MySQL手冊:

相關問題