0

Using Brian's suggestion below:

foreach($qs as $value){
                echo "<tr>".$value['qnum']." is the questions number and the question text is ".$value['qtext'].". The page and q values are ".$value['page']." and ".$value['questions']." respectively.</tr>";
        }

I get the following output from the array, which isn't right:

8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively

Any further suggestions.

Homer.

Hi again,

Thanks in advance for the help.

Here is my array based on $rowq:

Array (
 [0] => Array (
       [questions] => q8
       [qnum] => 8
       [qtext] => I know how what I do fits into my team's objectives
       [page] => 1
       )
 [1] => Array (
       [questions] => q8
       [qnum] => 8
       [qtext] => I know how what I do fits into my team's objectives
       [page] => 1
       ) 
 [2] => Array (
       [questions] => q8
       [qnum] => 8
       [qtext] => I know how what I do fits into my team's objectives
       [page] => 1
       ) 
 [3] => Array (
       [questions] => q8 
       [qnum] => 8
       [qtext] => I know how what I do fits into my team's objectives
       [page] => 1
       )
 [4] => Array (
       [questions] => q8
       [qnum] => 8
       [qtext] => I know how what I do fits into my team's objectives
       [page] => 1  
       )
 [5] => Array (
      [questions] => q8 
      [qnum] => 8 
      [qtext] => I know how what I do fits into my team's objectives
      [page] => 1 
      )
 [6] => Array (
      [questions] => q8 
      [qnum] => 8
      [qtext] => I know how what I do fits into my team's objectives
      [page] => 1
      )
 [7] => Array (
      [questions] => q8
      [qnum] => 8
      [qtext] => I know how what I do fits into my team's objectives
      [page] => 1
      ) 
 )

I would like to display elements of the array, looping through each row using (i think) the foreach statement but I can't get it working, ideally, I would like to echo something like this

echo "<tr>".$rowq[qnum]." is the questions number and the question text is ".$rowq[qtext].".  The page and q values are ".$rowq[page]." and ".$rowq[questions]." respectively.";

And that link of text would appear however many rows the array has in it.

Any and all advice appreciated - I'm struggling like heck to get my head around multi-dimensional arrays :(

Homer.

1
  • please copy the array structure from the shell or - when using the browser - copy it from the sourcecode of the page or wrap it in <pre> tags. And if you want to make it even easier for us, use var_export instead of print_r so we can reuse the array easily. Commented Apr 23, 2010 at 18:26

2 Answers 2

1

modifications from TriLLi

1) you don't need the $key since you never use it - in fact php will report a warning or notice

2) avoid using the error suppression operator, @, if you don't need to

3) also you wanted <tr> tags, right?

foreach($rowq as $value){
            echo "<tr><td>".$value['qnum']." is the questions number 
  and the question text is ".$value['qtext'].". The page and q values are".
$value['page']." and ".$value['questions']." respectively.</td></tr>";
    } 
Sign up to request clarification or add additional context in comments.

3 Comments

goog notice, I have forgot to escape tr tags so &lt; was ignored heheh thx
@brian_d - thanks - however there seems to be a problem - when I use that code...I get the following - see the above modification to the question.
I assume that the issue is not with the duplicated content as the array contains duplicated values. However for the alignment, it was my mistake not to wrap the row content in <td> tags. As well the <tr>s should be enclosed in <table> tags ie) <table> <tr><td></td></tr> <tr><td></td></tr> <tr><td></td></tr> </table>
0

use code as below foreach($rowq as $key => $value)
{
echo @"".$value['qnum']." is the questions number and the question text is ".$value['qtext'].". The page and q values are ".$value['page']." and ".$value['questions']." respectively.";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.