2017-07-24 109 views
0

我想创建一个使用MYSQL连接搜索两个表现在我想过滤一些变量,我已经从数据库调用了。

这个sql查询得到的一切,并粘贴在我的屏幕上

$sql2 = "select pinfo.*, einfo.* 
from profile_info pinfo , education_info einfo 
where pinfo.username = einfo.username"; 

现在我想过滤一些变数,说全名,出生日期,性别,位置,日期和恢复,INSTITUTION_NAME

现在信息保存在两个表我有写这个确切的查询来筛选两个表是一个问题

profile_info education_info

profile_info有此列 用户名

file_name 

file_size 

file_type  

tmp_name  

photograph_name  

photograph_size 

photograph_type       

photographtmp_name       

fullname        

address  
address2 
city      
state       

email       

tel       

state_origin        

lga       

marital_status       

dob 

和教育信息有这列

username    
    inst_name   
    inst_name2   
    grade   
    study_course     

    qualification   
    other_qualification   

    completion_year 

现在使用MYSQL像我如何能够过滤得到充足的结果。我已经写

到目前为止的代码看起来像这样

 <?php 
      if(isset($_POST['search_button'])) 
      { 
       require_once('inc/config.php'); 
       $con = mysqli_connect($host,$user,$pass,$db) or die ('Cannot Connect: '.mysqli_error()); 
       $sql = "select "; 
       $result = mysqli_query($con,$sql) or die("Error: ".mysqli_error($con)); 
       while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){ 

        echo " 
        <tr> 
         <td width=248 align=center> 
         <font face=Verdana size=2>".$row['fullname']."</font></td> 
         <td align=center><font face=Verdana size=2>".$row['dob']."</font></td> 
         <td align=center><font face=Verdana size=2>".$row['gender']."</font></td> 
         <td align=center><font face=Verdana size=2>".$row['location']."</font></td> 
         <td align=center><font face=Verdana size=2> 
         ".$row['resume']."</font></td> 
        </tr>"; 


       } 

      } 



      ?> 

回答

0

尝试。

实施例采取全名,地址从profile_info和等级以及合格从education_info

 $sql2 = "select profile_info.fullname as n, 
    profile_info.address as a, 
    education_info.grade as g, 
    eduction_info.qualification as q 
from profile_info inner join education info on profile_info.username=education_info.username";