警告:mysql_fetch_array()期望参数1是资源表无法获取数据

时间:2014-02-19 12:03:13

标签: php

<table width="1200px" class="flat-table flat-table-1">
                    <tbody>
                        <tr>
                            <th style="width:10px">Name</th>
                            <th style="width:200px">SSS#/LICENSE#</th>
                            <th style="width:5px">Offenses</th>
                            <th style="width:150px">Officer</th>
                            <th style="width:200px">Violation</th>
                              <th style="width:200px">Price</th>
                            <th style="width:200px">Last Update</th>
                        </tr>
                    </tbody>




         <?php
         date_default_timezone_set('Asia/Manila');
                        $conn=mysql_connect("localhost","root","");
                        mysql_select_db("dbposo",$conn);


            $violationz=mysql_query("select *,date_format(time,'%h:%i %p') as timed from tblviolator ORDER BY DDATE DESC");

                        while($data=mysql_fetch_array($violationz))
                            {
                                $license=$data['license'];
                                $link=str_replace(" ","-",$license);
                                $fname=$data['fname'];
                                $mname=$data['mname'];
                                $lname=$data['lname'];
                                $offenses=$data['offenses'];
                                $officer=$data['officer'];
                                $violation=$data['violation'];
                                $ddate=$data['ddate'];
                                $ttime=$data['ttime'];


                                print "
                                    <tr license='X$license'>
                                    <td width='10px'><center>$lname,$fname,$mname</center></td>
                                    <td width='200px'><center><a href='edit_publicviolation.php?n=$link'><font color='#00FF00'>$license</font></a></center></td>
                                    <td width='90px'><center>$offenses</center></td>
                                    <td width='170px'><center>$officer</center></td>
                                    <td width='230px'><center>$violation</center></td>
                                    <td width='200px'><center>$price</center></td>
                                    <td width='200px'><center>$ddate $ttime</center></td></tr>
                                    ";
                            }

                                    ?>  
    </table>

获取,而{我的错误是什么?要编辑什么?请指定我是编码的初学者,我不能帮助它:(请帮助吗?请提前感谢你  :)请帮助,您的答案非常感谢。抱歉我的英语不好&gt;。&lt;

3 个答案:

答案 0 :(得分:0)

试试这个:

ORDER BY DDATE DESC更改为ORDER BY ddate DESC

ddate小型大写

答案 1 :(得分:0)

你在sql中有错误。

您似乎在列名DDATE中有错误:

$violationz=mysql_query("select *,date_format(time,'%h:%i %p') as timed from tblviolator ORDER BY DDATE DESC");

列名称区分大小写: Are column and table name case sensitive in MySQL?

您还需要检查它是否已执行。

试试这个:

$violationz=mysql_query("select *,date_format(`time`,'%h:%i %p') as timed from tblviolator ORDER BY ddate DESC") or die(mysql_error()); 

答案 2 :(得分:0)

time是mysql的保留字,用于时间列的反引号

$violationz=mysql_query("select *,date_format(`time`,'%h:%i %p') as timed from tblviolator ORDER BY DDATE DESC");