0

When I execute a print_r I get this result...

Array ( 
    [0] => Array (
        [A_program_id] => a0F36000008PIYF
        [XC_program_logo] => louisville.jpg
    )
    [1] => Array (
        [A_program_id] =>  a0F36000008qjSp
        [XC_program_logo] => alabama.jpg
    )
    [2] => Array (
        [A_program_id] => a0F36000008pRxL
        [XC_program_logo] => trinity.jpg
    )
)

How do I make a while loop or whatever to properly fetch needed to query something like this:

//zero based
echo"".$rows[0][0]."</td><td>"".$rows[1][0].""</td><td>"".$rows[2][0]."";
echo"".$rows[0][1]."</td><td>"".$rows[1][1].""</td><td>"".$rows[2][1]."";

to show

louisville.jpg      alabama.jpg       trinity.jpg
a0F36000008PIYF     a0F36000008qjSp   a0F36000008pRxL

please help thx

Nick
  • 138,499
  • 22
  • 57
  • 95

1 Answers1

1

One possibility is to use array_column to extract each rows data from the source, and then implode to add the </td><td> between each value:

echo implode('</td><td>', array_column($rows, 'XC_program_logo'));
echo implode('</td><td>', array_column($rows, 'A_program_id'));

Demo on 3v4l.org

This will give the same output as the two echo statements in your question.

Nick
  • 138,499
  • 22
  • 57
  • 95