douyuqing_12345 2014-10-13 12:04
浏览 23

如何从mysql中的两个表中选择值

I want to display services table status='A', g1='G1'and add_servicess table g1='G1', type='E' titles.this is mysql query.

$services_sql="SELECT services.id, services.title,services.link,services.link_open,add_services.aid,add_services.tittle
FROM   services
LEFT JOIN add_services
ON  services.status='A' AND services.g1='G1' AND add_services.g1='G1' AND add_services.type='E'
";
$result = db::getInstance()->query($services_sql);
/*** loop over the results ***/
$chklogin_val = $result->rowCount();
foreach($result as $row) {
    if($acc_status=="A") {
        echo '<div class="servicebox">

        <div class="s_title"><h3>'.$row["title"].'</h3></div>

        <div class="s_img" ><a href="'.$row["link"].'" target="'.$row["link_open"].'" ><img width="'.$_SESSION['img_width'].'" height="'.$_SESSION['img_height'].'" src="service/'.$row["id"].'.jpg" /></a></div>
        </div> ';
        echo '<div class="servicebox">
        <div class="s_title"><a href="page.php?id='.$row['aid'].'" target="_blank"><h3>'.$row["tittle"].'</a></h3></div>
        </div> ';
    }
}

services table

add_services table

but its display same title in 2 times.eg i have column tittle "abc".it's display abc in two times.

  • 写回答

2条回答 默认 最新

  • dpsq8476 2014-10-13 12:11
    关注

    Shouldn't your query be:

    SELECT services.id, services.title, services.link, services.link_open, add_services.aid, add_services.tittle
    FROM   services
    LEFT JOIN add_services ON  AND services.g1 = add_services.g1 AND 
    WHERE services.status='A' and add_services.type='E' and services.g1 = 'G1'
    
    评论

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法