简体   繁体   English

Php - MySql 不从表中获取数据

[英]Php - MySql Not fetching datas from tables

I have a simple php sql script to display datas in datatable.我有一个简单的 php sql 脚本来显示数据表中的数据。
It displays the details of the children from tbl_child and fetch the latest course from the table_class and both the table are connected to l.childfkey=c.childpid.它显示来自 tbl_child 的孩子的详细信息并从 table_class 获取最新课程,并且两个表都连接到 l.childfkey=c.childpid。

here is the problem.这是问题所在。 the following script work well if i place如果我放置,以下脚本运行良好

$select = $pdo->prepare(" select * from tbl_child c .......................... ) $select = $pdo->prepare(" select * from tbl_child c ..................... )

but i dont need all the fields so if i mention only some fields it wont show the records from tbl_class.但我不需要所有字段,所以如果我只提到一些字段,它不会显示来自 tbl_class 的记录。

Here is the script which is not fetching from tbl_class这是未从 tbl_class 获取的脚本

$select = $pdo->prepare(" select 
                   childpid,
                   child_name,
                   child_surname,
                   child_birth,
                   child_age,
                                        
                   from tbl_child c 
                   
                   LEFT JOIN (SELECT classpid,childfkey,class_courseyear,class_course FROM tbl_class  where classpid IN (
                   
                    SELECT MAX(classpid)
                    FROM tbl_class 
                    GROUP BY childfkey
                   
                   
                   ))l ON l.childfkey=c.childpid

thanks in advance.提前致谢。

I noticed you use an alias in your child table tbl_child c but in the above, you select your column without the alias c .我注意到您在子表tbl_child c 中使用了别名,但在上面,您选择了没有别名c 的列。

Select column with the alias like:-选择具有别名的列,例如:-

c.childpid, c.child_name c.childpid, c.child_name

Thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM