It should be simple, but I just can't figure it out. I have a function, which returns an array, fetched from a MySql database. The returned array should have 2 elements.
Here is the function:
function path_to_photo ($id)
{
$query = mysql_query("Select path from photos1 where listingsdb_id = $id");
$test_array = mysql_fetch_array($query);
return $test_array;
}
$one=2;
$test = path_to_photo($one);
echo $test[0]; // --> this works fine
echo $test[1]; //-->this gives an error - undefined offset etc.
At first I thought my array returns actually only one element, but when I put
$query = mysql_query("Select path from photos1 where listingsdb_id=$id");
$test_array = mysql_fetch_array($query);
return sizeof($test_array);
it gives me correct number of 2. I just don't understand what happens with the second index. Here is the output of the query in MySQL
mysql> select path from photos1 where listingsdb_id=2;
+------------------+
| path |
+------------------+
| small_photo.jpg |
| big_photo.jpg |
+------------------+