0

below is a php object which is retrieving some values from mysql db through a php method

$query = "SELECT imgpath from images";

$oMySQL->ExecuteSQL($query);

Now when i use this

$result=$oMySQL->ExecuteSQL($query);

it prints "Array" How to iterate through the array

Regards Jane

3
  • 1
    I think you should review the basis of PHP. Commented Jul 16, 2013 at 7:56
  • Can you post that array. use for or foreach to iterate array Commented Jul 16, 2013 at 7:56
  • use foreach or for in php and iterate Commented Jul 16, 2013 at 7:56

2 Answers 2

2

A simple foreach loop.

foreach ($result as $key => $val) {
      foreach ($val as $label => $item) {
            echo $label . " - " . $item;
      }
}

$key will hold the associative name the array element, and $val will hold the value of the element.

Sign up to request clarification or add additional context in comments.

3 Comments

@DevZero it prints 0 - Array1 - Array2 - Array3 - Array4 - Array5 - Array6 - Array not the values
@JaneMarjana instead of echo, use print_r or var_dump functions
@JaneMarjana then you must loop again let me update my answer
2

You mean it print array when you do echo $result?

Then:

foreach($result as $index => $value) {
   echo $index . '=' $value;
}

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.