DrTrans Posted November 10, 2011 Share Posted November 10, 2011 Can someone help me figure out this query... I have it generating basically a list of whats in the database. One of the fields is numeric in database that i want it to read another table to get the correct variables. ( i hope i explain this right.. u might be able to see what i mean in the code). its fuxd. $connect = mysql_connect("localhost","root",""); mysql_select_db("magic"); $query = "SELECT * FROM props WHERE ownerid = '$ownerid' ORDER BY name ASC "; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $propertyid = $row['propid']; $propertyname = $row['name']; $propertydesc = $row['description']; $propertycity = $row['city']; $propertystate = $row['state']; $propertyzip = $row['zip']; $tenantid = $row['tenantid']; $active = $row['active']; $lease = $row['lease']; $leaseamt = $row['leaseamt']; if($active == "1"){ $propertystatus = "Active"; $query2 = "SELECT * FROM tenant WHERE propid = '$propid' "; $result2 = mysql_query($query2); while($row = mysql_fetch_assoc($result2)) { $tenantfname = $row['fname']; $tenantlname = $row['lname']; } } else { $propertystatus = "Unknown"; } print"<tr onMouseOver=\"this.bgColor = '#CEE3F6'\" onMouseOut =\"this.bgColor = '#FFFFFF'\"> <td align=\"left\" width=\"25%\" onclick=\"window.open('viewpropdetail.php?prop=$propertyid','mywindow','width=1200,height=600,scrollbars=1')\">$propertyname</td><td>$tenantfname $tenantlname</td><td>$propertystatus</td><td>$$leaseamt</td> "; } Quote Link to comment Share on other sites More sharing options...
trq Posted November 10, 2011 Share Posted November 10, 2011 Executing queries within a loop is very inefficient. You should read this: http://www.phpfreaks.com/tutorial/data-joins-unions Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.