Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

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()

thanks

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