如何从2个表中检索数据? [英] How to retrieve data from 2 tables?

查看:129
本文介绍了如何从2个表中检索数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人在这里知道如何加入2表吗?我在语法上仍然有错误我不知道什么,错误在哪里。我想要的是从不同的表中获取这个具体的数据。请帮助!

Does someone here know how to join 2 tables? I keep having an error in terms of the syntax I don't know what and where is the error. All I want is to get this specific data from different tables. Please Help!

<?php
echo"<ul>";
$sql="select product_title.products, qty.cart from  products Inner Join cart on product_id.procucts=p_id.cart ";

$query = mysql_query($sql);

while($row = mysql_fetch_array($query))
    echo"
    <center>Summary of orders <br><br>
        <li>Your Order: $row[0]</li>
        <li>Quantity: $row[1]</li>
    </center><br/>";
echo"</ul>";
?>


推荐答案

这是第一个答案的解释(由KinjaMistry)。

This is explain for first answer (by KinjaMistry).

您必须始终是代码语法!您必须始终以大写写保留的SQL字。您必须始终格式化代码。这会避免将来出现此类问题和错误。

You must be code grammar always! You must write reserved SQL words in uppercase always. You must format your code always. This avoid such problems and errors in future.

SELECT
        cart.qty,
        products.product_title
    FROM cart /* select first from cart beacause here cart is "parent" data */
    INNER JOIN products /* join "dependency" data */
        ON products.product_id = cart.p_id /* compare as dependency<->parent (like native: you<-above->friend) */

这篇关于如何从2个表中检索数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆