gpt4 book ai didi

php - MySql select from 3 tables Undefined index 错误

转载 作者:行者123 更新时间:2023-11-30 22:10:13 24 4
gpt4 key购买 nike

我有 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)

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

( ! ) Notice: Undefined index: scn in C:\wamp\www\order\projectmanagment\transferred.php on line 48 Call Stack #TimeMemoryFunctionLocation 10.0021260912{main}( )..\transferred.php:0 ( ! ) Notice: Undefined index: sucm in C:\wamp\www\order\projectmanagment\transferred.php on line 49 Call 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_suppliertbl_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>';

最佳答案

我认为您的查询应该是:

SELECT concat(db_fname,' ',db_lname) as fname , 
S.db_CompanyName as scn, SC.db_CompanyNam as sucn
FROM tbl_user U, tbl_supplier S, tbl_subcontractor SC

关于php - MySql select from 3 tables Undefined index 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40316564/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com