I am brand new to PHP. I'm attempting to simply query a database, get 2 records, store the 2 records (with 2 columns) in an array to later access them (without looping).
My code:
$query="SELECT id, word FROM images ORDER BY lastVote LIMIT 0, 2";
$result = @mysql_query($query) or die('Error, query failed: ' . mysql_error());
$array = array();
if ($result = mysql_query($query)) {
if (mysql_num_rows($result)) {
while ($row = mysql_fetch_assoc($result)) {
$array[] = $row;
}
}
}
var_dump($array);
The output from the var_dump:
array(2) { [0]=> array(2) { ["id"]=> string(1) "1" ["word"]=> string(8) "wildfire" } [1]=> array(2) { ["id"]=> string(1) "2" ["word"]=> string(6) "kungfu" } }
I simply later in the web page want to access the data "1", "wildfire" and then later on "2", "kungfu"...
How do I got about accessing this data? Thanks so much.
-J