解析错误:语法错误,意外T_IF

时间:2014-04-14 09:51:05

标签: php mysql

我已经被这个问题困住了一个星期左右,我似乎无法绕过它。我举起手来承认我不是最好用PHP所以任何帮助非常感谢..我想要实现的是一个下拉菜单,有3个类别' All&# 39;,'击剑'和'车道'。选择后,我希望根据该类别显示特定图像,显然当“全部”图像显示时。被选中以显示表中的每个图像..我将MySQL表设置为'图像'有3列; ' id',' Img'和'类别'。

编辑:警告:mysqli_fetch_array()要求参数1为mysqli_result,第80行/home1/wlarter/public_html/portfolio.php中给出布尔值

while($ row = mysqli_fetch_array($ result))

<FORM action="portfolio.php" method="post">
 <SELECT onload="displayProject(this.value);" onchange="displayProject(this.value);">
  <OPTION VALUE='none'>ALL</OPTION>
  <OPTION VALUE='1'>Fencing</OPTION>
  <OPTION VALUE='2'>Driveway</OPTION>
 </SELECT>
</FORM>

<?php 

$db = new mysqli('localhost', 'wlarter_user', 'pw', 'wlarter_portfolio');

if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}

$option= $_POST['option'];

$queries = "SELECT * FROM image";
if ($option != 'none'){
 $queries = "SELECT * FROM image where category=".$option
}

$queries=$query;
$result=@mysqli_query($db,"$query");

while($row = mysqli_fetch_array($result))
{
?>

<div class="box-portfolio"> <?php echo $row['Img']; ?> </div>


<?php
}
mysqli_close($db);
?>

3 个答案:

答案 0 :(得分:2)

$queries = "SELECT * FROM image";
if ($option != 'none'){
 $queries = "SELECT * FROM image where category=".$option
}

您在查询后错过了分号;

此外,末尾的while循环缺少一个结束大括号(范围分隔符)}

while($row = mysqli_fetch_array($result))
{
?>

<div class="box-portfolio"> <?php echo $row['Img']; ?> </div>


<?php
}

答案 1 :(得分:1)

您需要在;之后添加$queries以及使用while关闭}循环:

$queries = "SELECT * FROM image"; // <-- Add ; here
if ($option != 'none'){
 $queries = "SELECT * FROM image where category=".$option
}
$queries=$query;
$result=@mysqli_query($db,"$query");
while($row = mysqli_fetch_array($result))
{
?>
<div class="box-portfolio"> <?php echo $row['Img']; ?> </div>
<?php
} // <-- Add } here
mysqli_close($con);
?>

答案 2 :(得分:0)

用这个替换你的php代码,你有语法错误

<?php 

$db = new mysqli('localhost', 'wlarter_user', 'pw', 'wlarter_portfolio');

if($db->connect_errno > 0)
{
    die('Unable to connect to database [' . $db->connect_error . ']');
}

$option= $_POST['option'];

$queries = "SELECT * FROM image"; //code updated
if ($option != 'none')
{
     $queries = "SELECT * FROM image where category=".$option; //code updated
}

$queries=$query;
$result=@mysqli_query($db,"$query");

while($row = mysqli_fetch_array($result))
{
?>
    <div class="box-portfolio"> <?php echo $row['Img']; ?> </div>
<?php
}                       //code updated
mysqli_close($con);
?>