Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php mysql和内部连接复制结果_Php_Mysql_Inner Join - Fatal编程技术网

使用php mysql和内部连接复制结果

使用php mysql和内部连接复制结果,php,mysql,inner-join,Php,Mysql,Inner Join,我有三个下拉列表,其中包含从3个不同表的数据库中检索到的值 省: 治理率 省名 地区: 区号 地区名称 村庄: 身份证件 村名 成员: 用户id 用户名 省 地区 村庄 我想要的是,当用户选择三个下拉列表中的一个或全部下拉列表时,系统必须显示与所选列表相关的结果 但问题是,当用户从省中选择时,它工作正常,但当用户选择省和地区时,它会复制与所选值相关的结果,如果用户选择省地区和村庄,结果会变成三倍 有人能帮我吗 我将显示这三种类型的所有代码 如果有人抱怨,尽量不要打我 代码: 各省 按地区 按村庄

我有三个下拉列表,其中包含从3个不同表的数据库中检索到的值

省:

治理率 省名 地区:

区号 地区名称 村庄:

身份证件 村名 成员:

用户id 用户名 省 地区 村庄 我想要的是,当用户选择三个下拉列表中的一个或全部下拉列表时,系统必须显示与所选列表相关的结果 但问题是,当用户从省中选择时,它工作正常,但当用户选择省和地区时,它会复制与所选值相关的结果,如果用户选择省地区和村庄,结果会变成三倍

有人能帮我吗

我将显示这三种类型的所有代码

如果有人抱怨,尽量不要打我

代码: 各省 按地区 按村庄
有几件简单的事情值得一试:

echo或var_转储$_POST结果,以确保获得您认为获得的数据。这可能是问题的原因。你可能会得到不止一个

看起来最有可能的原因是混乱的代码。您有三个输出部分,因此您有三个可能的输出,所有这些都可以在满足适当的IF条件时触发。试着在每个区块内重复“这里”、“那里”和“无处不在”或您选择的单词-您很快就会看到可疑代码在哪里

更好的选择可能是将where子句更改为以下内容:

WHERE village='[villagename from post]' OR district='[districtname from post'] OR governorate='[govname from post]'
这样,您只需要一个IF和一个输出。它的伸缩性也更好

尝试使用手动插入的测试数据运行每个sql PHP myAdmin非常方便,并查看问题是在sql还是PHP级别

@-尽量避免。最好以不产生错误的方式编写代码。你把它放在那里是为了一个空的索引错误吗?如果是这样,这可能是你的问题。检查您的HTML并查看上面的答案1


所以不是一个代码审查网站。你应该试着解决问题,展示你所做的,并提出一个有针对性的问题。在常见问题解答中,您将找到如何提问的提示。不需要敲打。只需在每次查询结束时重复使用分组。请问,专业化表是什么?它的内容有可能增加你的结果集的基数吗?@Ollie Jones我不明白你的问题
 if($_POST['listbyqa']=="by_dist")
   {
      @ $bydist = $_POST['district'];
       $sql = mysql_query("SELECT user_id,first_name, last_name, birth_date, registered_date, 
    s.specialization_name,
    g.governorate_name,
    d.district_name,
    v.village_name 
          FROM members u
                       INNER JOIN  specialization s 
                        ON u.specialization = s.specialization_id
                        INNER JOIN governorate g
                        ON u.governorate = g.governorate_id
                        INNER JOIN districts d
                        ON u.district = d.district_id
                        INNER JOIN village v
                        ON u.village = v.id
                       WHERE district = '$bydist'")or die(mysql_error("Error: querying the district"));

       $num_row = mysql_num_rows($sql);
       if($num_row > 0 )
       {
           while($row = mysql_fetch_array($sql))
           {
              $row_id = $row['user_id'];
              $row_first_name =  $row['first_name'];
              $row_last_name =  $row['last_name'];
              $row_birthdate =  $row['birth_date'];
              $row_registered_date = $row['registered_date'];
              $row_spec = $row['specialization_name'];
              $row_gov = $row['governorate_name'];
              $row_dist = $row['district_name'];
              $row_village = $row['village_name'];

                ////***********for the upload image*************************//
         $check_pic="members/$row_id/image01.jpg";
         $default_pic="members/0/image01.jpg";
         if(file_exists($check_pic))
         {
             $user_pic="<img src=\"$check_pic\"width=\"120px\"/>";
         }
         else
         {
             $user_pic="<img src=\"$default_pic\"width=\"120px\"/>";
         }

          $outputlist.='
     <table width="100%">
                 <tr>
                    <td width="23%" rowspan="5"><div style="height:120px;overflow:hidden;"><a href =              "http://localhost/newadamKhoury/profile.php?user_id='.$row_id.'" target="_blank">'.$user_pic.'</a></div></td>
                    <td width="14%"><div  align="right">Name:</div></td>
                    <td width="63%"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$row_id.'" target="_blank">'.$row_first_name.' '.$row_last_name.'</a></td>
                    </tr>

                    <tr>
                      <td><div align="right">Birth date:</div></td>
                      <td>'.$row_birthdate.'</td>
                    </tr>
                    <tr>
                     <td><div align="right">Registered:</div></td>
                     <td>'.$row_registered_date.'</td>
                    </tr>

                    <tr>
                     <td><div align="right">Job:</div></td>
                     <td>'.$row_spec.'</td>
                    </tr>

                    <tr>
                     <td><div align="right">Location:</div></td>
                     <td>'.$row_gov.'__'.$row_dist.'__'.$row_village.'</td>
                    </tr>
                    </table>
                    <hr />
            ';

           }
       }

   }
   else
   {
       $errorMSG = "No member within this selected District";
   } 
if($_POST['listbyqb']=="by_city")
   {
       echo $_POST['listbyqb'];
      @ $byvillage = $_POST['village'];
       $sql = mysql_query("SELECT user_id,first_name, last_name, birth_date, registered_date, 
    s.specialization_name,
    g.governorate_name,
    d.district_name,
    v.village_name 
          FROM members u
                       INNER JOIN  specialization s 
                        ON u.specialization = s.specialization_id
                        INNER JOIN governorate g
                        ON u.governorate = g.governorate_id
                        INNER JOIN districts d
                        ON u.district = d.district_id
                        INNER JOIN village v
                        ON u.village = v.id
                       WHERE village = '$byvillage'")or die(mysql_error("Error: querying the district"));

       $num_row = mysql_num_rows($sql);
       if($num_row > 0 )
       {
           while($row = mysql_fetch_array($sql))
           {
              $row_id = $row['user_id'];
              $row_first_name =  $row['first_name'];
              $row_last_name =  $row['last_name'];
              $row_birthdate =  $row['birth_date'];
              $row_registered_date = $row['registered_date'];
              $row_spec = $row['specialization_name'];
              $row_gov = $row['governorate_name'];
              $row_dist = $row['district_name'];
              $row_village = $row['village_name'];

                ////***********for the upload image*************************//
         $check_pic="members/$row_id/image01.jpg";
         $default_pic="members/0/image01.jpg";
         if(file_exists($check_pic))
         {
             $user_pic="<img src=\"$check_pic\"width=\"120px\"/>";
         }
         else
         {
             $user_pic="<img src=\"$default_pic\"width=\"120px\"/>";
         }

          $outputlist.='
     <table width="100%">
                 <tr>
                    <td width="23%" rowspan="5"><div style="height:120px;overflow:hidden;"><a href =              "http://localhost/newadamKhoury/profile.php?user_id='.$row_id.'" target="_blank">'.$user_pic.'</a></div></td>
                    <td width="14%"><div  align="right">Name:</div></td>
                    <td width="63%"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$row_id.'" target="_blank">'.$row_first_name.' '.$row_last_name.'</a></td>
                    </tr>

                    <tr>
                      <td><div align="right">Birth date:</div></td>
                      <td>'.$row_birthdate.'</td>
                    </tr>
                    <tr>
                     <td><div align="right">Registered:</div></td>
                     <td>'.$row_registered_date.'</td>
                    </tr>

                    <tr>
                     <td><div align="right">Job:</div></td>
                     <td>'.$row_spec.'</td>
                    </tr>

                    <tr>
                     <td><div align="right">Location:</div></td>
                     <td>'.$row_gov.'__'.$row_dist.'__'.$row_village.'</td>
                    </tr>
                    </table>
                    <hr />
            ';

           }
       }

   }
   else
   {
       $errorMSG = "No member within this selected District";
   }
}
WHERE village='[villagename from post]' OR district='[districtname from post'] OR governorate='[govname from post]'