简体   繁体   English

如何从具有相同列名的多个表中检索数据

[英]How to retrieve data from multiple table having same column name

I need help. 我需要帮助。 I'm well aware that there are similar questions on (Google/stackoverflow) and I got many information from that helped me to move forward but I'm stuck somewhere, I think on "where' statement. Seems like I don't get it right that's the reason of this post. 我很清楚(Google / stackoverflow)上也有类似的问题,我从中获得了很多信息,这有助于我前进,但是我被困在某个地方,我想写“ where”声明。好像我没明白没错,这就是这篇文章的原因。

I need to get data from many tables having same column name. 我需要从具有相同列名的许多表中获取数据。 Please below's my code I've written so far. 请在下面是我到目前为止编写的代码。

$result = $connection->query("select price.ID as id1, price.ID as id2 from tbladventure, tblafrica where price>='$pricefrom' and price <='$priceto'");

for ($i = 0;$i<$result->num_rows;$i++){
$row = $result->fetch_array(MYSQLI_NUM);
      echo $row['id1']."<br>";
      echo $row['id2']."<br>";
}

Below's the Web Interface 以下是Web界面

enter image description here 在此处输入图片说明

在where条件下使用tablename.columnname

$result = $connection->query("select price.ID as id1, price.ID as id2 from tbladventure, tblafrica where tbladventure.price>=".$pricefrom." and tblafrica.price <=".$priceto);
select price.ID as id1, price.ID as id2 from tbladventure, tblafrica where price>='$pricefrom' and price<='$priceto'

In your select, 1st ID should come from table "price". 您选择的第一个ID应该来自“价格”表。 2nd ID should come from table "price". 第二个ID应该来自表格“价格”。 Q: why would you do that ? 问:为什么要这么做?

Then, you use "tbladventure" and "tblafrica", but select no rows from those tables. 然后,您使用“ tbladventure”和“ tblafrica”,但从这些表中不选择任何行。

You request seems very badly thought : what do you exactly need to do ? 您的要求似乎非常糟糕:您到底需要做什么?

What does request returns ? 请求返回什么? any error message ? 任何错误信息?

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

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