It’s caused by there not being any jokes returned by the database. When there’s jokes in the database they get placed into the $jokes array but if there is no jokes then $jokes is just an empty string. To solve it, just before the line where you access the result set, add this line:
$jokes=array();
That will set $jokes up as an empty array, if there are jokes they’ll be added to the $jokes array, if there aren’t any jokes then the $jokes array will be empty and the foreach loop will see an empty array.
@HAWK can the appropriate person at HQ please fix this error? It seems to come up with every edition of Kevin’s book
Ok thank you.
I have try to add $jokes=array( ); before <?php foreach ($jokes as $joke): ?>, but when add a new joke and refresh the page, the joke not view.