2013-12-21 60 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手册:

相关问题