问题描述
我有两个表第一个是 cont_details
i have two tablesthe first one is cont_details
-------------- --------------
| cont_details_id | cont_no |
-----------------------------
| 1 | A001 |
| 2 | A002 |
| 3 | A003 |
------------------------------
第二个是 cont_sold_tmp
--------------
| id | cont_no |
--------------
| 1 | 1 |
| 2 | 3 |
----------------
现在我需要从 temp_cont
所以我用了这个查询
select * from cont_details left join cont_sold_tmp on cont_details.cont_details_id = cont_sold_tmp.cont_no where cont_sold_tmp.cont_no is null
当我检入PhpmyAdmin但在HTMl中使用它时,此查询非常有效
This query works perfectly when i check in PhpmyAdmin but when i use it in HTMl, not working
<select name="cont_no" id="cont_no" data-rel="chosen">
<option value="">Select</option>
<?php
$qry = mysql_query("select * from cont_details left join cont_sold_tmp on cont_details.cont_details_id = cont_sold_tmp.cont_no where cont_sold_tmp.cont_no is null");
while($res = mysql_fetch_array($qry))
{
?>
<option value="<?php echo $res["cont_details_id"];?>">
<?php echo $res["cont_no"];?>
</option>
<?php } ?>
</select>
数据库连接运行良好,而不是联接查询,我只是用简单的查询" select * from cont_details "进行了检查,它显示了所有记录.但是当我使用这个联接查询.我在下拉菜单中没有任何记录
Database connections are working perfectly, instead of join query i just checked with the simple query "select * from cont_details" its shows all the records. but when i use this join query. i dont get any records in dropdown
推荐答案
最后发现了我所做的错误-_-
And finally found the mistake what i did -_-
select cont_details.cont_details_id as cont_details_id,
cont_details.cont_no as cont_no
from cont_details left join cont_sold_tmp
on cont_details.cont_details_id = cont_sold_tmp.cont_no
where cont_sold_tmp.cont_no is NULL
合并表格后,我没有正确选择表格名称为(.)的列
after combining tables, i didn't choose column correctly with table name (.)
所以我使用时的结果<option value="<?php echo $res["cont_details_id"];?>">
,它不会在那里退出,因此显示为空
so the result when i use<option value="<?php echo $res["cont_details_id"];?>">
, it doesnt exits there so its show empty
感谢您的回复:-)
这篇关于Mysql查询可在Phpmyadmin中使用,但不适用于PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!