逻辑错误或语法错误?

时间:2016-09-09 03:18:02

标签: php mysql

我想在结果页面中执行一个查询,该查询选择大于表单数据从索引页面传递的信息。

从索引页面传递的值是正确的,如下所示:

Array
(
[device] => sim only
[provider1] => umobile
[plantype] => postpaid
[dusage] => 3
[cusage] => 0
[musage] => 300
)

但我的结果显示不如预期。我想知道是我的逻辑错误还是我的语法错误?

这是我的查询代码:

 <?php
                //$planquery="SELECT * FROM plan";
                $dquery= "SELECT * FROM details";
                $device = $_POST['device'];
                $provider1 = $_POST['provider1'];
                //$provider2 = $_POST['provider2'];
                //$provider3 = $_POST['provider3'];
                //$provider4 = $_POST['provider4'];
                $plantype = $_POST['plantype'];
                $dusage = $_POST['dusage'];
                $cusage = $_POST['cusage'];
                $musage = $_POST['musage'];
                $planquery="SELECT * FROM plan WHERE 
                            Phone='$device' AND SIMTYPE='$plantype' AND 'DATA'>='$dusage' AND 'CALL'>='$cusage' AND 'MSG'>='$musage' "; 
                $planresult=mysql_query($planquery) or die ("Query to get data from firsttable failed: ".mysql_error());
                $dresult=mysql_query($dquery) or die ("Query to get data from firsttable failed: ".mysql_error());
                //$sresult=mysql_query($squery) or die ("Query to get data from firsttable failed: ".mysql_error());
                while ((($prow = mysql_fetch_assoc($planresult))) && ($drow = mysql_fetch_assoc($dresult)) ) {

                ?>

我有两个细节

  1. 500 free msg
  2. 200 free msg
  3. 表单数据包含用户搜索要求,以防用户搜索500msg。我想要做的查询只是选择当'MSG'&gt; ='$ musage'时还有其他要求的记录。两个结果都显示为结果;这不是预期的。

1 个答案:

答案 0 :(得分:0)

(代表OP发布解决方案)

我通过重组表解决了这个问题,因此查询更容易。我使用左连接,而不是从两个表中拉出来。