Hi folks!
I have a table with about 3 rows and 4 columns. Each column has a unique name.
I want to take all the data from one specific column; we'll call it "pet_names".
owner | pet_type | pet_names | pet_age
john bird penelope 2
barbara cat kittybop 6
tommy dog rover 3
You get the idea.
I want to get all of the pet names and put them in an array and then retrieve each item in the array, one after another, separated by break tags. Here's what I'm doing, minus all the database connection nonsense, which I have excluded:
$thisdb = "my_database";
$thistable = "pet_stuff";
$query = "SELECT pet_name FROM " . $thistable;
$query_result = mysql_db_query($thisdb, $query);
$pet_name_array = mysql_fetch_array($query_result, MYSQL_ASSOC);
foreach ($pet_name_array as $petname) {
echo "$petname <br />\n";
}
This works, but only for the first pet name, not all three. I consulted the SQL documentation and in the examples they give, this select query selects an entire column, not just the first entry in the column, which is what is happening when I use the above code.
Any ideas?
THanks!