I'm new to coding.
CONTEXT I have one table 'online_event' that holds the details to my event page. I have another table 'event_gallery' that holds the photos to the same event page. The primary key in 'online_event' is the foreign key in 'event_gallery'
so one event from 'online_event' can have multiple photos inside the 'event_gallery' table.
I'm able to retrieve one photo in the event_gallery table by using the foreign key (which is just the event id).
My question is, how can I call all pictures? it's only echoing the first of 3 photos i have saved in the table with that id number.
$gallery_table = Eventgallery::find_by_id($_GET['id']);
if($gallery_table){
$images = $gallery_table->image_name;
}
print_r($images);
Here is the function that retrieves the data
public static function find_by_id($id){
global $database;
$the_result_array = static::find_by_query("SELECT * FROM " . static::$db_table. " WHERE id = $id");
return !empty($the_result_array) ? array_shift($the_result_array) : false; //ternary operator
}
Because the method is returning an array_shift, shouldn't the variable I created ($images) be an array? When I print_r() it comes out as just 1 result, not an array.
Once I have it as an array, i want to loop through it and echo it all out.
Thank you
array_shift()on the result array.array_shift()removes the first element from a provided array and returns its value. If you want the entire array don't usearray_shift()on it. return it as it is.