php查询失败'订单子句'

时间:2016-06-10 04:28:13

标签: php mysql

我的php项目出错了。错误如下。 我怎么解决这个问题?我没有太多的PHP经验

注意:查询失败:'order clause'中的未知列'P.id'

警告:mysql_fetch_object():提供的参数不是有效的MySQL结果资源

 <?php
            $search= "";
            if(isset($_POST['btnsearch']))
            {
                $search="WHERE p.product_description LIKE '%".$_POST['search']."%'";
            }
            else
            {
                $search="";
            }

            $query = mysql_query("SELECT
                                        p.id,
                                        p.product_description,
                                        p.product_category,
                                        p.album_name,
                                        p.date,
                                        pd.product_name
                                        FROM 
                                        product AS p
                                        INNER JOIN product_detail AS pd ON p.id = pd.product_id
                                        ".$search." 
                                        GROUP BY p.id
                                        ORDER BY P.id ASC
                                        ") or trigger_error('Query Failed: ' . mysql_error());

            while ($row = mysql_fetch_object($query)) 
            {
                ?> 

                                <tr>
                                    <td><img style="width:100px; height=100px;" src="<?php echo 'upload/' .$row->product_name?>"></td>
                                    <td class="center"><?php echo $row->album_name  ?></td>
                                    <td class="center"><?php echo $row->product_description  ?></td>
                                    <td class="center"><?php echo $row->product_category  ?></td>
                                    <td class="center">
                                        <?php echo $row->date ?>
                                    </td>
                                    <td class="center">

                                        <a class="btn btn-info" href="edit.php?id=<?php echo $row->id ?>">
                                            <i class="halflings-icon white edit"></i>  
                                        </a>
                                        <a class="btn btn-info" href="view.php?id=<?php echo $row->id ?>">
                                            <i class="halflings-icon white edit"></i>  
                                        </a>
                                        <a class="btn btn-danger" onclick="return confirm('Are you sure to delete this Image ?');" href="delete.php?id=<?php echo $row->id  ?>">
                                            <i class="halflings-icon white trash"></i> 
                                        </a>
                                    </td>
                                </tr>


                        <?php
                            }

                        ?>

1 个答案:

答案 0 :(得分:1)

区分大小写?尝试使用ORDER BY p.id ASC更改ORDER BY P.id ASC