简体   繁体   中英

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.

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

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". 2nd ID should come from table "price". Q: why would you do that ?

Then, you use "tbladventure" and "tblafrica", but select no rows from those tables.

You request seems very badly thought : what do you exactly need to do ?

What does request returns ? any error message ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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