Jump to content

Query only returns one row of data - how to fix?


JTapp

Recommended Posts

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>");
}
}
?>

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.