php脚本问题

时间:2011-05-10 03:48:40

标签: php

   <html>
   <body> 

   <?php 
   $con = mysql_connect("localhost","chamara","");
   if (!$con)
  {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ban", $con);
$result = mysql_query("SELECT * FROM basic");
while($row = mysql_fetch_array($result)) {------------###---------->>>>>this line
echo $row['lisitem'] . " - " . $row['lisforhowmany'];
echo "<br />";                      
 ?>
</body> 

</html>

Dreamweavercs5使用此脚本向我显示结束body标记附近的错误。 当我评论下面的行时,dreAMVEAVER没有显示错误

while($ row = mysql_fetch_array($ result)){

这条线有什么问题?

3 个答案:

答案 0 :(得分:7)

嗯,你没有for while循环的结束括号(})。

// ...
while($row = mysql_fetch_array($result)) 
{
    echo $row['lisitem'] . " - " . $row['lisforhowmany'];
    echo "<br />";  
}
// ...

答案 1 :(得分:4)

您忘记关闭while循环的括号。

在php脚本的末尾或任何需要的位置添加}

答案 2 :(得分:1)

<html>
<body>  

<?php 
 $con = mysql_connect("localhost","chamara","");
 if (!$con)
   die('Could not connect: ' . mysql_error());
 mysql_select_db("ban", $con);
 $result = mysql_query("SELECT * FROM basic");
 while($row = mysql_fetch_array($result)) //{ in this case you dont need a bracket
   echo $row['lisitem'] . " - " . $row['lisforhowmany'].'<br />';                      
?>

</body> 
</html>