spock9458 Posted August 22, 2014 Share Posted August 22, 2014 I have a membership directory that I've been working with for a long time, and recent server upgrades with MySQL, PHP, etc. forced me to do some recoding. While I was doing that, I wanted to try and make some improvements. I must give a brief description of the intent, and then the results I got, so someone can sort out the problem for me. I have a query that selects all "Agent" members, then orders them by County, then by Company Name. What I am trying to do is create a new heading in my list every time the County information changes as the list is sorted and output to my table. I am going to attache 2 .php files with my code. The agent_member_list.php is the original code that pulls all of the members properly, and results can be viewed here: http://www.nmlta.org/MemberDirectory/agent_member_list.php The agent2_member_list.php is where I'm trying to insert the new conditional statement to print my County headings when a new County is encountered in the results. The heading actually works, and changes correctly, but the problem is that the first member entry in every county is not printed in the output. I know the query is correct, so I'm sure I've got the conditional "if" for checking County field wrong, or misplaced. Here is the link to it: http://www.nmlta.org/MemberDirectory/agent2_member_list.php I'm hoping someone can spot my error pretty quickly, I only dabble in this very rarely. Thanks for any help! agent2_member_list.php agent_member_list.php Quote Link to comment https://forums.phpfreaks.com/topic/290601-where-do-i-place-my-conditional-statement/ Share on other sites More sharing options...
ginerjm Posted August 22, 2014 Share Posted August 22, 2014 Took a quick look (something I don't usually do - look at att. files) and see some pretty lengthy code with queries inside your loops. Not good. Work on joining you queries up into one. Also - do you not know what the ! operator is? You constantly write if conditions that only have an else to them and no code for the 'true' condition. Try doing the reverse, as in if (!empty(xxx)) and drop the do nothing part and the else clause Your question refers to your insistence on fetching the first row before you begin your loop. That's where you are losing the first entry. Set your test variable to 'xxx' and then begin your loop without retrieving a row. The way you do it now you have already set your test var when the second row is retrieved so therefor if the county matches you won't have that first heading. Quote Link to comment https://forums.phpfreaks.com/topic/290601-where-do-i-place-my-conditional-statement/#findComment-1488649 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.