Hi, Im trying to print out section titles and instructions from a database, however the first section title gets printed twice, I've no idea what I'm doing wrong.

Here's a code snippet:

$query = $this->db->query('SELECT DISTINCT SectionTitle FROM SECTION WHERE SurveyID= '.$number );
            $j=1;
            foreach ($query->result() as $row)
        {
            $secTitle=  $row->SectionTitle;
            echo $secTitle;
            echo "<br>";


            $query2= $this->db->query('SELECT DISTINCT Instructions FROM SECTION WHERE SectionID='. $j.' AND SurveyID= '.$number );
            $j++;
            foreach ($query2->result() as $row2)
            {
            $instr=  $row2->Instructions;
            echo $instr;
            echo "<br>";

            }


        }

And heres my output :

BASIC DEMOGRAPHIC INFORMATION
Your answers to the following questions will be used to customize the cyber security awareness training program to fit a specific user group within your environment.
BASIC DEMOGRAPHIC INFORMATION
Your answers to the following questions will be used to make the training material more fun.
HISTORY AND BACKGROUND - GENERAL
Your answers to the following questions will be used to determine the current level of technology usage within your environment.
HISTORY AND BACKGROUND - TECHNOLOGY
Your answers to the following questions will be used to determine the current level of cyber security awareness and understanding within your environment. Please do not leave out any questions. If you are unsure a the correct answer, choose the answer that you feel might be the right answer.
SPECIFIC SCENARIOS
This information will be used to identify any topics additional to those already identified.
OPEN SECTION



BASIC DEMOGRAPHIC INFORMATION is printed twice, I cant seem to figure out why.

Please ignore this post, I had a minor problem in my database. It's solved now, the code was fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.