-1

3種類の検索があります

  • 行政によって

  • 地区別

  • 都市別

    ユーザーが知事を選択するたびに、システムは正しい答えを表示します

ただし、ユーザーが地区を選択すると、結果が複製されます。つまり、同じ結果が表示され、選択した地区または村に関連する結果が表示されます。

しかし、私が望むのは、すべてではなく、選択した地区または県または村を持つユーザーを表示することです

コード:

<?php
    if(isset($_POST['listbyq']))
    {    
    //********************by governorate**************************************//
       if($_POST['listbyq']=="by_gov")
       {
           $bygov = $_POST['governorate'];
           $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 governorate = '$bygov'")or die(mysql_error("Error: querying the governorate"));
           
           $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 governorate";
       }
     //*****************************by District***************************************//  
       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";
       } 
    
    //****************************by Village**************************************//
    if($_POST['listbyqb']=="by_city")
       {
          @ $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";
       }
    }

?>
4

1 に答える 1

1

最も詳細なデータのみを表示する場合は、条件構造を次のようにする必要があります。そうしないと、条件が満たされているそれぞれのデータが実行されます。

if ($_POST['listbyqb']=="by_city") {...}
else if ($_POST['listbyqa']=="by_district") {...}
else if ($_POST['listbyq']=="by_ governorate") {...}
else {...}
于 2016-08-11T19:44:27.453 に答える