phpita — 2013-10-10T05:31:00-04:00 — #1
I'm studying from the book of which the author is Kevin Yank,
I'm in chapter 5, the book advised me to turn to this forum.
I'm doing the exercise using two separate databases so as to practice both with the example from the book and be with my idea,
For now I posted the picture with the error that I'm from, someone can tell me yours? :shifty:
phpita — 2013-10-10T08:25:52-04:00 — #2
molona — 2013-10-11T03:03:21-04:00 — #3
Sorry but images need to get approved and we do check from time to time but if you think that we're taking too long, do get in touch with a member of the staff and send him a pm asking him to do so.
I can't really see what's wrong. Your error clearly indicates that there's something missing in your foreach() and probably is a variable (jokes) that has no value.
Now, you say that this is a book written by Kevin Yank. He wrote several books but because you're talking about "jokes", I think that this book in particular is "Build your own database driven website with PHP and MySQL"
Chapter 5 is dedicated to the relationships between tables. Could it be the case that the table jokes was completely empty?
guido2004 — 2013-10-11T04:49:02-04:00 — #4
Please post the php code, so we can take a look
spacephoenix — 2013-10-11T04:58:48-04:00 — #5
If I remember the code correctly $jokes is the array that the jokes returned from the database is loaded into. A foreach loop expects to be given an array to iterate (loop) through, but when there are no jokes returned by the query, all it sees is an empty variable instead.
Just before you grab the result set, add this:
That will set up the $jokes variable as an empty array, ready to have any jokes returned by the database added to it. I'm surprised that the error has not been corrected by now as it's existed in the last two editions of the book at least. @HAWK; Could you please raise it with whoever at hq deals with errors/errata in SitePoint books? ty
phpita — 2013-10-11T08:36:46-04:00 — #6
thanks for reply
I found that did not work because I had the authors table in the database EMPTY: D
.. so I solved the problem. But it is also true that the book does not warn: D
hawk — 2013-10-13T19:25:34-04:00 — #7
1119 — 2013-10-14T03:57:22-04:00 — #8
Well readin that "Error" the first one is telling you that $jokes is not defined and thats your problem to start with. You should check you code to see that you have infact got an array called $jokes defined then take it from there.
phpita — 2013-10-14T13:45:47-04:00 — #9
foreach ($result as $row)
$jokes = array(
'id' => $row['id'],
'news' => $row['testonotizia'],
'name' => $row['name'],
'email' => $row['email']
molona — 2013-10-14T14:03:04-04:00 — #10
Aaaaaaah! This is so much better! Thank you @phpita;
The thing is that I cannot always have access to the text directly so seeing your code helps.
Still, since you've solved the problem (well done to you :D)... Am I right to assume that you don't need further help? (at least, for the moment?)
phpita — 2013-10-14T15:49:41-04:00 — #11
No, thanks, i continue study