Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Inserting MySQL table outputs into there own arrays

I have a MySQL table submitting data from a form into a table on another page

while($row = mysql_fetch_row($result)){
    echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td></tr>";

thats the basic code that i used to produce the table. I want to get $row[2] into its own array so that I can isolate the data submitted by the form.

Ive tried the foreach command with no success.

Thanks for your help

3 Answers

You shouldn't be using mysql_ functions. They're deprecated. Use PDO instead, or at least mysqli.

Just curious, did treehouse teach the mysql_ functions in their php tutorial?

thanks for your help. And no, I'm learning this by myself.

Oh I see. In your while before the echo statement add:

array_push($myarray, $row[2])

make sure you define $myarray outside of the while loop. Then all of your row 2 entries are stored in that array.

Define it like this outside your while loop:

$myarray = array()


can you tell me how to echo the data from the array thanks