| | |
Regarding Mysql Query
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2008
Posts: 1
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: May 2005
Posts: 514
Reputation:
Solved Threads: 19
You probably want to use PHP for this.
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.
MySQL Syntax (Toggle Plain Text)
$q="select * from table2"; $r=mysql_query($q); while ($row = mysql_fetch_array($r)){ $status=$row['status']; $id=$row['id']; $phone=$row['phone']; $email=$row['email']; $q2="select * from table1 where id ='$id'"; $r2=mysql_query($q2); while ($row2 = mysql_fetch_array($r2)){ $id=$row2['id]'; $name=$row['name']; $address=$row2['address']; 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.
![]() |
Similar Threads
- test mysql query for no results (PHP)
- Double MySQL Query (PHP)
- Python Tuples and Mysql Query (MySQL)
- MySQL query's (MySQL)
- Change MySQL Query Timeout Period (MySQL)
- simply generate user front end for mysql ? (MySQL)
- Please help me out with MySQL query (MySQL)
- Invision Power Board mysql error when trying to view newly created forums (PHP)
Other Threads in the MySQL Forum
- Previous Thread: plz help me..mysql_fetch_array() problem
- Next Thread: Foreign Keys
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm data database design developer development distinct drupal dui email enter enterprise eudora facebook form foss gartner gnu government gpl greenit groupware hiring hyperic images innerjoins insert ip joebrockmeier join keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization





