Jump to content

Recommended Posts

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

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.

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.