Need another set of eyes to my gutted code

Thread Solved

Join Date: Feb 2008
Posts: 36
Reputation: jtapp is an unknown quantity at this point 
Solved Threads: 0
jtapp jtapp is offline Offline
Light Poster

Need another set of eyes to my gutted code

 
0
  #1
Feb 24th, 2008
First of all, please forgive my immature code.. I am a beginner and this is my first one.
Could some body take a look at this and tell me why the data in my table is not populating?
Thanks in advance for your time.

The problem I am having is all variables are populating, with the exception of variables 20-24. Variables 1-19 are coming from a table called tblLodges and variables 20-24 are coming from a table called tblOfficers

  1. $id = $_GET['id'];
  2.  
  3. $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());
  4. while ($row = @mysql_fetch_array($query))
  5.  
  6. {
  7. $variable1=$row["strLodgeName"];
  8. $variable2=$row["intLodgeNumber"];
  9. $variable3=$row["strDistrictName"];
  10. $variable4=$row["strLodgeWEB"];
  11. $variable5=$row["strLodgeCounty"];
  12. $variable6=$row["dtChartered"];
  13. $variable7=$row["strLodgeMailingAddress"];
  14. $variable8=$row["strLodgeMailingAddress2"];
  15. $variable9=$row["strLodgeMailingCity"];
  16. $variable10=$row["strLodgeMailingStateCode"];
  17. $variable11=$row["strLodgeMailingPostCode"];
  18. $variable12=$row["strLodgeEmail"];
  19. $variable13=$row["strLodgePhone"];
  20. $variable14=$row["strLodgeFax"];
  21. $variable15=$row["strDrivingDirectons"];
  22. $variable16=$row["dtMeetingTime"];
  23. $variable17=$row["dtMealTime"];
  24. $variable18=$row["strFloorSchool"];
  25. $variable19=$row["strLodgeNews"];
  26. $variable20=$row["strOfficerTitle"];
  27. $variable21=$row["strFirstName"];
  28. $variable22=$row["strLastName"];
  29. $variable23=$row["BusinessPhone"];
  30. $variable24=$row["PersEmail"];
  31.  
  32. //layout for Lodge Information results
  33.  
  34. echo ("<tr>");
  35. echo "<center>\n";
  36. echo "<p>GRAND LODGE OF LOUISIANA - LODGE LOCATOR RESULTS\n</p>";
  37. echo "Lodge Name:$variable1</p>";
  38. echo "<p><b>Lodge Number:</b> $variable2</p>";
  39. echo "<p><b>District Name:</b> $variable3</p>";
  40. echo "<a href=\"$variable4\">Click Here To Go To The Lodge Website</a>";
  41. echo "<p><b>Lodge County:</b> $variable5</p>";
  42. echo "<p><b>Lodge Chartered On:</b> $variable6</p>";
  43. echo "<p><b>Lodge Address:</b> $variable7, $variable8</p>";
  44. echo '<p>' . $variable9 . $variable10 . $variable11 . '</p>';
  45. echo "Click Here To Email The Lodge";
  46. echo "<p>Lodge Phone Number: $variable13, Lodge FAX Number: $variable14</p>";
  47. echo "<p>Lodge Driving Directions: $variable15</p>";
  48. echo "<p>Lodge Lodge Meeting Time: $variable16</p>";
  49. echo "<p>Lodge Lodge Meal Time: $variable17</p>";
  50. echo "<p>Lodge Floor School: $variable18</p>";
  51. echo "<p>Lodge News: $variable19</p>";
  52. echo "<img src='{$row['link']}'>";
  53. echo "</center>\n";
  54. echo ("</tr>");
  55. }
  56.  
  57. //Layout for Officers Table Results
  58.  
  59. echo "<center>\n";
  60. echo "<H2>Roster of Lodge Officers</H2>\n";
  61. echo "<table border='1'>
  62. <tr>
  63. <th>Officer Title</th>
  64. <th>Officer First</th>
  65. <th>Officer Last</th>
  66. <th>Officer Email</th>
  67. <th>Officer Phone</th>
  68.  
  69. </tr>";
  70.  
  71. if (mysql_num_rows($query)) {
  72. while ($row = mysql_fetch_array($query)){
  73. $variable20=$row["strOfficerTitle"];
  74. $variable21=$row["strFirstName"];
  75. $variable22=$row["strLastName"];
  76. $variable23=$row["PersEmail"];
  77. $variable24=$row["BusinessPhone"];
  78.  
  79. //table layout for results
  80.  
  81. print ("<tr>");
  82. echo "<tr align=\"center\" bgcolor=\"#EFEFEF\">\n";
  83. echo "<td class=\"td_id\">$variable20</td>\n";
  84. echo "<td class=\"td_id\">$variable21</td>\n";
  85. echo "<td class=\"td_id\">$variable22</td>\n";
  86. echo "<td class=\"td_id\">$variable23</td>\n";
  87. echo "<td class=\"td_id\">$variable24</td>\n";
  88. print ("</tr>");
  89. }
  90. }
  91.  
  92. ?>
Last edited by MattEvans; Feb 24th, 2008 at 12:18 pm. Reason: Added code tags.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 36
Reputation: jtapp is an unknown quantity at this point 
Solved Threads: 0
jtapp jtapp is offline Offline
Light Poster

Half of my variables aren't populating - but the data is there...

 
0
  #2
Feb 24th, 2008
The difference in the variables is 1-19 are coming from a table called tblLodges and they are working fine, but variables 20-24 are coming from a table called tblOfficers and nothing is working....
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Need another set of eyes to my gutted code

 
0
  #3
Feb 24th, 2008
As far as I can see, both are coming from the same 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
. Check if your query is returning the rows you want to use. As far as I know, when you are using the resultset in the first while, the pointer will be pointing to the last record. So, I dont think in the second while loop, the recordset will remain the same.
Well, execute the query again before the second while. ie., $query=mysql_query("your query");
and use the while loop.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 36
Reputation: jtapp is an unknown quantity at this point 
Solved Threads: 0
jtapp jtapp is offline Offline
Light Poster

Re: Need another set of eyes to my gutted code

 
0
  #4
Feb 24th, 2008
Wow - I'm sorry.. I'm not understanding your suggestion (newbie). I can tell you yes, both are coming from the same query... and the query is returning the rows I want, but it is missing some of the data. Starting at line 71 the code is supposed to pull data from a different table (tblOfficers).

I'm wondering if I just need an additional query that finds the unique ID number from the first query. If so, I'm screwed because I have no idea how to do that.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Need another set of eyes to my gutted code

 
0
  #5
Feb 24th, 2008
Okay.. I ll make it simple for you.. Here is an example of what you are doing.
  1. <?php
  2. mysql_connect("localhost",'root');
  3. mysql_select_db("test");
  4. $q="select * from table1";
  5. $res=mysql_query($q); //result set of the query
  6. while($row=mysql_fetch_array($res)){ //loop and get all the records for the above query
  7. echo "first loop".$row[0]."<br />";
  8. } //by the end of this query, the internal pointer will be pointing towards the last record.
  9. while($row=mysql_fetch_array($res)){ //loop for the same resultset.
  10. echo "second loop".$row[1]."<br />";
  11. } //prints nothing since the pointer is already pointing at the last record in the previous loop.
  12. ?>

To make that work, you need to execute your query again. Like this.
  1. <?php
  2. mysql_connect("localhost",'root');
  3. mysql_select_db("test");
  4. $q="select * from table1";
  5. $res=mysql_query($q);
  6. while($row=mysql_fetch_array($res)){
  7. echo "first loop".$row[0]."<br />";
  8. }
  9. $q="select * from table1";
  10. $res=mysql_query($q);
  11. while($row=mysql_fetch_array($res)){
  12. echo "second loop".$row[1]."<br />";
  13. }
  14. ?>
Notice the difference. Well, Try this code.
  1. <?php
  2. $id = $_GET['id'];
  3.  
  4. $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());
  5. while ($row = @mysql_fetch_array($query)) {
  6. $variable1=$row["strLodgeName"];
  7. $variable2=$row["intLodgeNumber"];
  8. $variable3=$row["strDistrictName"];
  9. $variable4=$row["strLodgeWEB"];
  10. $variable5=$row["strLodgeCounty"];
  11. $variable6=$row["dtChartered"];
  12. $variable7=$row["strLodgeMailingAddress"];
  13. $variable8=$row["strLodgeMailingAddress2"];
  14. $variable9=$row["strLodgeMailingCity"];
  15. $variable10=$row["strLodgeMailingStateCode"];
  16. $variable11=$row["strLodgeMailingPostCode"];
  17. $variable12=$row["strLodgeEmail"];
  18. $variable13=$row["strLodgePhone"];
  19. $variable14=$row["strLodgeFax"];
  20. $variable15=$row["strDrivingDirectons"];
  21. $variable16=$row["dtMeetingTime"];
  22. $variable17=$row["dtMealTime"];
  23. $variable18=$row["strFloorSchool"];
  24. $variable19=$row["strLodgeNews"];
  25. $variable20=$row["strOfficerTitle"];
  26. $variable21=$row["strFirstName"];
  27. $variable22=$row["strLastName"];
  28. $variable23=$row["BusinessPhone"];
  29. $variable24=$row["PersEmail"];
  30.  
  31. //layout for Lodge Information results
  32.  
  33. echo ("<tr>");
  34. echo "<center>\n";
  35. echo "<p>GRAND LODGE OF LOUISIANA - LODGE LOCATOR RESULTS\n</p>";
  36. echo "Lodge Name:$variable1</p>";
  37. echo "<p><b>Lodge Number:</b> $variable2</p>";
  38. echo "<p><b>District Name:</b> $variable3</p>";
  39. echo "<a href=\"$variable4\">Click Here To Go To The Lodge Website</a>";
  40. echo "<p><b>Lodge County:</b> $variable5</p>";
  41. echo "<p><b>Lodge Chartered On:</b> $variable6</p>";
  42. echo "<p><b>Lodge Address:</b> $variable7, $variable8</p>";
  43. echo '<p>' . $variable9 . $variable10 . $variable11 . '</p>';
  44. echo "Click Here To Email The Lodge";
  45. echo "<p>Lodge Phone Number: $variable13, Lodge FAX Number: $variable14</p>";
  46. echo "<p>Lodge Driving Directions: $variable15</p>";
  47. echo "<p>Lodge Lodge Meeting Time: $variable16</p>";
  48. echo "<p>Lodge Lodge Meal Time: $variable17</p>";
  49. echo "<p>Lodge Floor School: $variable18</p>";
  50. echo "<p>Lodge News: $variable19</p>";
  51. echo "<img src='{$row['link']}'>";
  52. echo "</center>\n";
  53. echo ("</tr>");
  54. }
  55.  
  56. //Layout for Officers Table Results
  57.  
  58. echo "<center>\n";
  59. echo "<H2>Roster of Lodge Officers</H2>\n";
  60. echo "<table border='1'>
  61. <tr>
  62. <th>Officer Title</th>
  63. <th>Officer First</th>
  64. <th>Officer Last</th>
  65. <th>Officer Email</th>
  66. <th>Officer Phone</th>
  67.  
  68. </tr>";
  69. $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());
  70. if (mysql_num_rows($query)) {
  71. while ($row = mysql_fetch_array($query)){
  72. $variable20=$row["strOfficerTitle"];
  73. $variable21=$row["strFirstName"];
  74. $variable22=$row["strLastName"];
  75. $variable23=$row["PersEmail"];
  76. $variable24=$row["BusinessPhone"];
  77.  
  78. //table layout for results
  79.  
  80. print ("<tr>");
  81. echo "<tr align=\"center\" bgcolor=\"#EFEFEF\">\n";
  82. echo "<td class=\"td_id\">$variable20</td>\n";
  83. echo "<td class=\"td_id\">$variable21</td>\n";
  84. echo "<td class=\"td_id\">$variable22</td>\n";
  85. echo "<td class=\"td_id\">$variable23</td>\n";
  86. echo "<td class=\"td_id\">$variable24</td>\n";
  87. print ("</tr>");
  88. }
  89. }
  90. ?>
Cheers,
Naveen
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 36
Reputation: jtapp is an unknown quantity at this point 
Solved Threads: 0
jtapp jtapp is offline Offline
Light Poster

Re: Need another set of eyes to my gutted code

 
0
  #6
Feb 24th, 2008
Naveen,

Thank you very much. That seems to be quite close to the resolution. I'm getting some of the data in my table.

However, I am getting one row of data and for the test run that I did I should have two... is there a limit or something that is going on here?
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 36
Reputation: jtapp is an unknown quantity at this point 
Solved Threads: 0
jtapp jtapp is offline Offline
Light Poster

Re: Need another set of eyes to my gutted code

 
0
  #7
Feb 24th, 2008
the field "lngLodgeID" is the unique ID field name...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Need another set of eyes to my gutted code

 
0
  #8
Feb 24th, 2008
Maybe your query is wrong ? Did you execute it in phpmyadmin/mysql ? Did you get the output which you desired ? I don't know what your query does. Umm.. Execute it first and change it ! limit 50 will show only 50 records! You are grouping the records by name. Maybe thats why you are getting only 1 record ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 36
Reputation: jtapp is an unknown quantity at this point 
Solved Threads: 0
jtapp jtapp is offline Offline
Light Poster

Re: Need another set of eyes to my gutted code

 
0
  #9
Feb 24th, 2008
I took out the WHERE and GROUP BY clause and was able to get a return of multiple rows. Problem now is they are not unique to the field "lngLodgeID"- Here is what I now have:

$query = mysql_query("SELECT tblLodges.strLodgeName, tblLodges.intLodgeNumber, tblLodges.strDistrictName, tblLodges.strLodgeMailingCity, tblLodges.strLodgeMailingPostCode, tblLodges.strLodgeCounty, 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());
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 36
Reputation: jtapp is an unknown quantity at this point 
Solved Threads: 0
jtapp jtapp is offline Offline
Light Poster

Re: Need another set of eyes to my gutted code

 
0
  #10
Feb 24th, 2008
I don't know if you care, but here is the history on how I got to where I am..

http://www.daniweb.com/forums/thread110398.html
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum


Views: 1061 | Replies: 17
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC