MySql从3个表中选择未定义的索引错误

时间:2016-10-29 06:09:42

标签: php mysql

我有3个表 tbl_user,tbl_supplier,tbl_subcontractor

我想从

中选择这些行

tbl_user db_fname,db_lname ),

tbl_supplier db_CompanyName ),

tbl_subcontractor db_CompanyName

我正在使用此查询

SELECT concat(db_fname,' ',db_lname) as fname from tbl_user)
      UNION 
      (SELECT db_CompanyName as scn from tbl_supplier)
      UNION 
      (SELECT db_CompanyName as sucn from tbl_subcontractor)

它给了我正确的结果,但也给了我这个错误

  

(!)注意:未定义的索引:scn in   第48行的C:\ wamp \ www \ order \ projectmanagment \ transferred.php调用   Stack #TimeMemoryFunctionLocation 10.0021260912 {main}(   ).. \ transferred.php:0(!)注意:未定义的索引:sucm in   第49行的C:\ wamp \ www \ order \ projectmanagment \ transferred.php调用   Stack #TimeMemoryFunctionLocation 10.0021260912 {main}(   ).. \ transferred.php:0

此查询的结果将显示在选择菜单上,如下所示:

echo'<select name="txt_transferredto" class="states">';
      while($row=mysqli_fetch_array($q)){
         $fname=$row['fname'];
         $companyname=$row['scn'];
         $subcompanyname=$row['sucm'];
      if($fname!=""){
       echo"<option value='$fname'>";echo $fname;echo"</option>";}
    else if($subcompanyname!=""){      
        echo"<option value='$subcompanyname'>";echo $subcompanyname;echo"</option>";}
    else if($companyname!=""){      
        echo"<option value='$companyname'>";echo $companyname;echo"</option>";}
      }
      echo'</select>';
此菜单中的

显示结果,但也显示错误

我可以从此菜单中选择数据从 tbl_user 获取并执行我想要的操作,但如果我选择数据从 tbl_supplier tbl_subcontractor获取数据我无能为力(更新或选择或......)

我测试sql并给我结果,但我不知道这是什么问题 如何解决这个问题

$q=mysqli_query($conn,"SELECT concat(db_fname,' ' , db_lname) as fname from tbl_user ") or die(mysqli_error($conn));
 $qq= mysqli_query($conn,"SELECT db_CompanyName as scn from tbl_supplier") or die(mysqli_error($conn));
 $qqq= mysqli_query($conn,"SELECT db_CompanyNamee as sucn from tbl_subcontractor") or die(mysqli_error($conn));

  echo'<select name="txt_transferred" class="form-control inpu-md">';
 echo'<option value="">--SELECT--</option>';
  while($row=mysqli_fetch_array($q) and $roww=mysqli_fetch_array($qq) and $rowww=mysqli_fetch_array($qqq)){
     $fname=$row['fname'];
     $companyname=$roww['scn'];
     $subcompanyname=$rowww['sucn'];
  if($fname!=""){
   echo"<option value='$fname'>";echo $fname;echo"</option>";}
else if($subcompanyname!=""){      
    echo"<option value='$subcompanyname'>";echo $subcompanyname;echo"</option>";}
else if($companyname!=""){      
    echo"<option value='$companyname'>";echo $companyname;echo"</option>";}
  }

  echo'</select>';

1 个答案:

答案 0 :(得分:0)

我认为你的查询应该是:

EMail