php - f3框架sql查询联接

原文 标签 php fat-free-framework

f3 framework sql query join

I have the following tables:

tbl_users
===============
uid
username
password
gid

tbl_groups
===============
gid
name
type

I am trying to figure out how to use the sqlmapper in f3 to be able to query both tables where username equals $_POST["username"] and be able to get the group name and type as well. Is it possible to join like queries using this framework with sqlmapper?

I've been searching around and can't find any examples on that.

Answer

you can try to setup some virtual fields for this:

$mapper->group_name = 'select name from tbl_groups where tbl_groups.gid=tbl_users.gid';
$mapper->group_type = 'select type from tbl_groups where tbl_groups.gid=tbl_users.gid';
$mapper->load(array('uid = ?',123));

echo $mapper->group_name;

翻译

我有以下表格:

tbl_users
===============
uid
username
password
gid

tbl_groups
===============
gid
name
type


我试图弄清楚如何在f3中使用sqlmapper来查询用户名等于$ _POST [“ username”]的两个表,并能够获取组名和类型。使用此框架和sqlmapper可以像查询一样联接吗?

我一直在搜索,找不到任何示例。
最佳答案
您可以尝试为此设置一些虚拟字段:

$mapper->group_name = 'select name from tbl_groups where tbl_groups.gid=tbl_users.gid';
$mapper->group_type = 'select type from tbl_groups where tbl_groups.gid=tbl_users.gid';
$mapper->load(array('uid = ?',123));

echo $mapper->group_name;
相关推荐

php - PHP Regex:匹配字符集或字符串结尾

php - PHP / MySQL平均基于数组的内容

php - 如何使用PHP将图像发送到deviantsart rest API

php - Laravel关系返回null

php - Laravel:按特定ID排序

php - ssh2_exec:等待进程的下一个运行

javascript - 在提交时从查询中删除美元符号

php - 获取三个数组的所有可能组合,而不重复

php - Symfony2 Twig获取子实体的总数

php - MySQL查询删除行,如果两列相等