hi all,

i have two tables, table1(id, name, address) and table2(id, phone, email, status). now i want to fetch data from both tables and display in a table. what i want is data must be fetched from table1 and table2 when the status in table2 is 1. if status in table2 is 0 then it do not fetch data from table2 but shows data of table1. can anybody tell me how can i fetch data in this case.

help me please.

Gitesh Chawla

9 Years
Discussion Span
Last Post by techniner

You probably want to use PHP for this.

$q="select * from table2";
while ($row = mysql_fetch_array($r)){
            $q2="select * from table1 where id ='$id'";
            while ($row2 = mysql_fetch_array($r2)){
            if ($status == 1){
            echo "$name - $address - $phone - $email";
            } elseif($status == 0){
            echo "$name - $address";

I think your logic is flawed. We must look in table2 to find out if status = 1 or not.

In your original request you said you did not want to fetch the data. I think you meant that you did not want to "display" the data.

Anyhow the above code should do what you want.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.