English 中文(简体)
工作成果
原标题:Empty results with Where Clause
  • 时间:2012-05-11 16:25:06
  •  标签:
  • mysql
  • php

我对根据搜索表格显示“访问”表的结果有问题!

这里是法典!

                <?php

                $date1 = $_POST[ day ] . "-" . $_POST[ month ] . "-" . $_POST[ year ];
                $date2 = $_POST[ day1 ] . "-" . $_POST[ month1 ] . "-" . $_POST[ year1 ];
                $product=$_POST[ product ];
                $region=$_POST[ region ];
                $speciality=$_POST[ speciality ];
                $type=$_POST[ visit_type ];

$query="SELECT id, name, seller_1_name, seller_2_name FROM visits Where (speciality = $speciality ) AND (type = $type ) AND (product = $product ) AND (date BETWEEN  $date1  AND  $date2 )";
$num=mysql_numrows($result);
$row = mysql_fetch_array($result);

?>

<h3> Showing results where Product is <?php echo $product; ?>, Speciality is <?php echo $speciality ?>, Region is <?php echo $region ?> and Type is <?php echo $type ?>.</h3>
        <table class="auto-style4" style="width: 100%" border="1"><tr>
        <td style="height: 18px">ID</td>
        <td style="height: 18px">Name</td>
        <td style="height: 18px">seller one name</td>
        <td style="height: 18px">seller 2 name</td>   
        </tr>
        <tr>
        <?php
$i=0;
while ($i < $num) {


$f1=mysql_result($result,$i,"id");
$f2=mysql_result($result,$i,"name");
$f4=mysql_result($result,$i,"seller_1_name");
$f5=mysql_result($result,$i,"seller_2_name");

?>        
        <td><?php echo $f1; ?> </td>
        <td><?php echo $f2; ?> </td>
        <td><?php echo $f4; ?></td>
        <td><?php echo $f5; ?></td>
         </tr>

<?php
$i++;
}
?>  

该表以正确的变量显示标题,但表中的错误代码为:

警告:我的sql_numrows(以英语发言):所提供的论据不是MySQL在175条线上产生/home/ebarea/public_html/.../.../results_submitt.php的有效结果资源

警告:我的sql_fetch_array():所提供的论据不是M.SQL在M.SQL第176条线上提供的资源。

妇女权利行动组织

最佳回答

您从未执行过mysql_query/code>。 可能的话题是:

$query="SELECT id, name, seller_1_name, seller_2_name FROM visits Where (speciality = $speciality ) AND (type = $type ) AND (product = $product ) AND (date BETWEEN  $date1  AND  $date2 )";
$result=mysql_query($query); ## This line is new.
$num=mysql_numrows($result);
$row = mysql_fetch_array($result);

为了确定日期问题,你可能需要明确告诉我的SQL有关日期。 例如:

$query="SELECT 
            id, name, seller_1_name, seller_2_name
        FROM visits 
        WHERE
            (speciality = $speciality ) AND
            (type = $type ) AND
            (product = $product ) AND
            (date BETWEEN DATE( $date1 ) AND DATE( $date2 ))";

然而,正如其他人指出的,你用来把你的变量集中起来的守则很容易受到射电车攻击,而且应该真正得到更新。

问题回答

没有

$result = mysql_query($query);

before

$num=mysql_numrows($result);
$row = mysql_fetch_array($result);

You just forget to run mysql_query before:

$result = mysql_query($query);
$num = mysql_numrows($result);

这可以帮助你处理多行,id,不要忘记我的s。 此外,让用户投入使用也是明智的,因为现在,你完全容易注射。

$query = mysql_query($sql, $conn);
$total = mysql_num_rows();
while ( $row = mysql_fetch_object() )
{
   $data[] = $row;
}
foreach( $data as $r )
{
  echo "<td>".$r->id."</td>";
  echo "<td>".$r->name."</td>";
  echo "<td>".$r->seller_1_name."</td>";
  echo "<td>".$r->seller_2_name."</td>";
}              




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签