很多站长朋友们都不太清楚php多表联查语句,今天小编就来给大家整理php多表联查语句,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 PHP如何实现多表联查并且将特定标签的内容替换成别的 2、 php多表关联查询 3、 在thinkphp3.2中怎么写多表连接查询 4、 Thinkphp3.2怎么写多表查询语句 5、 PHP 多表关联查询怎么写 PHP如何实现多表联查并且将特定标签的内容替换成别的先查询出表a中question_detial字段,再通过php正则匹配获取标签[attach]1[/attach]中的ID,通过该ID查询表b,获取到file_location字段,然后通过php(str_replace)替换掉question_detial中的标签[attach]1[/attach]
$sql = 'select * from `表A` where 条件';
$res = mysql_query($sql);
$data = mysql_fetch_assoc($res);
$question_detial = $data['question_detial'];
preg_match_all('/\[attach\]([0-9]*)\[\/attach\]/',$question_detial,$match);
if(isset($match[1]) $match[1]){
$str_search = null;
$str_replace = null;
foreach($match[1] as $key => $val){
$str_search[$key] = '[attach]'.$val.'[/attach]';
$str_replace[$key] = '';
$sql_b = "select file_location from `表B` where id=".$val;
$res_b = mysql_query($sql_b);
$row_b = mysql_fetch_assoc($res_b);
$str_replace[$key] = '<img src="'.$row_b['file_location'].'" />';
}
$data['question_detial'] = str_replace($str_search,$str_replace,$question_detial);
}
print_r($data);
php多表关联查询在这句代码
"FROM " . $GLOBALS['ecs']->table('order_goods')." AS og, ".$GLOBALS['ecs']->table('order_info')." AS oi ".
后面加(注意点号的连接):
" LEFT JOIN ". $GLOBALS['ecs']->table('goods') . "AS g ON og.goods_id = g.goods_id ".
然后在开头的sql语句后面这里加上你要的字段:
$sql = 'SELECT og.goods_id, og.goods_sn, og.goods_name,og.goods_attr, og.goods_number AS goods_num, og.goods_price, g.gonghuojia '.
最后你去测试看一下行不行.
在thinkphp3.2中怎么写多表连接查询以一个 user 表和 jifen 表联查为例,,
第一种方式:
$data = M('user as a')->join('jifen as b on b.id = a.id')->where('a.id = 1')->select();
第二种:
$data = M()->table('user as a')->join('jifen as b on b.id = a.id')->where(' a.id = 1 ')->select();
如果有多个表,继续在table 后面加 join 就行了
Thinkphp3.2怎么写多表查询语句$Model = M('Artist');
$Model->join('think_work ON think_artist.id = think_work.artist_id')
->join('think_card ON think_artist.card_id = think_card.id')->select();
PHP 多表关联查询怎么写你是三个表吗?
order 的orderid 对应order_goods的orderid
order_goods的goodsid 对应 goods的id
然后你是想通过产品ID查询订单出来?
SELECT * FROM order WHERE orderid IN (select og.orderid from order_goods og left join goods g ON og.goodsid = g.id)
关于php多表联查语句的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php多表联查语句 php数据库联表查询的详细内容...