JTapp Posted February 25, 2008 Share Posted February 25, 2008 Does anybody know what I need to add to the following query to get it to return more than one row of data? <?php $query = mysql_query("SELECT a.strLodgeName, a.intLodgeNumber, a.strDistrictName, a.strLodgeWEB, a.strLodgeCounty, a.dtChartered, a.strLodgeMailingAddress, a.strLodgeMailingAddress2, a.strLodgeMailingCity, a.strLodgeMailingStateCode, a.strLodgeMailingPostCode, a.strLodgeEmail, a.strLodgePhone, a.strLodgeFax, a.strDrivingDirectons, a.dtMeetingTime, a.dtMealTime, a.strFloorSchool, a.strLodgeNews, b.strOfficerTitle, b.strFirstName, b.strLastName, b.BusinessPhone, b.PersEmail FROM tblLodges a LEFT JOIN tblOfficers b ON a.lngLodgeID = b.lngLodgeID WHERE a.intLodgeNumber=$id GROUP BY a.strLodgeName LIMIT 50")or die(mysql_error()); if (mysql_num_rows($query)) { while ($row = mysql_fetch_array($query)){ $variable20=$row["strOfficerTitle"]; $variable21=$row["strFirstName"]; $variable22=$row["strLastName"]; $variable23=$row["PersEmail"]; $variable24=$row["BusinessPhone"]; //table layout for results print ("<tr>"); echo "<tr align=\"center\" bgcolor=\"#EFEFEF\">\n"; echo "<td class=\"td_id\">$variable20</td>\n"; echo "<td class=\"td_id\">$variable21</td>\n"; echo "<td class=\"td_id\">$variable22</td>\n"; echo "<td class=\"td_id\">$variable23</td>\n"; echo "<td class=\"td_id\">$variable24</td>\n"; print ("</tr>"); } } ?> Quote Link to comment Share on other sites More sharing options...
p2grace Posted February 25, 2008 Share Posted February 25, 2008 With the code the way it is, the query could be returning many results but the variables keep getting overwritten on each one, so it only looks like it's returning one result. Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 25, 2008 Share Posted February 25, 2008 if (mysql_num_rows($query)>0) { while ($row = mysql_fetch_assoc($query)){ Quote Link to comment Share on other sites More sharing options...
JTapp Posted February 25, 2008 Author Share Posted February 25, 2008 redarrow - That didn't change anything, but thanks for looking at it. p2grace - Ok - any suggestions on how I can make the code more efficient...? I'm super new at this... Quote Link to comment Share on other sites More sharing options...
JTapp Posted February 25, 2008 Author Share Posted February 25, 2008 Hey guys - I'm going crazy. The query is supposed to match a unique ID field ("lngLodgeID") from a table called tblLodges and to the same field in a table called tblOfficers and return some rows. When I first posted, I had a WHERE clause and only got one result when there were a couple more to report. I took out the WHERE clause and now my problem is unique rows are not being returned - but I'm getting several rows. ??? ??? ??? $query = mysql_query("SELECT tblLodges.strLodgeName, tblLodges.intLodgeNumber, tblOfficers.strOfficerTitle, tblOfficers.strFirstName, tblOfficers.strLastName, tblOfficers.BusinessPhone, tblOfficers.PersEmail FROM tblLodges LEFT JOIN tblOfficers ON tblLodges.lngLodgeID = tblOfficers.lngLodgeID LIMIT 0, 50")or die(mysql_error()); 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.