Prev: fetching DB entries
Next: Stripping Characters
From: Mike Davies on 22 Jun 2010 10:17 Hello, This is my first post to this list and I am a novice at php coding. I can generally follow the code but not good at writing from scratch. I have recently been trying to add to a website which was originally developed by someone else and is written in php and mysql. I am trying to add a 'news' section to the site. This would be similar to an existing 'projects' section so, rather than write it completely from scratch I copied the php and the database tables from the 'project' section and renamed 'project' to 'news'. This is working well except for one thing â I get the following error messages when looking at the detailed news item. This code does not produce this warning in the project section which is using the same php code Warning: reset() [function.reset]: Passed variable is not an array or object in /home/b23aadf/public_html/news/details.php on line 72 Warning: Variable passed to each() is not an array or object in /home/b23aadf/public_html/news/details.php on line 73 The relevant lines are : 72 reset($thumbsarray); 73 while (list($key, $value) = each($thumbsarray)) { The site is at www.aadf.co.uk and select 'News'. Is anyone able to help resolve this? If you let me know what further information you require I can provide it. Mike Davies -- Mike Davies Integra Web Design, Rhynie, By Huntly, AB54 4LS 01464 861535 www.integrawebdesign.co.uk
From: Jim Lucas on 22 Jun 2010 10:38 Mike Davies wrote: > Hello, > > This is my first post to this list and I am a novice at php coding. I > can generally follow the code but not good at writing from scratch. > > > I have recently been trying to add to a website which was originally > developed by someone else and is written in php and mysql. I am trying > to add a 'news' section to the site. This would be similar to an > existing 'projects' section so, rather than write it completely from > scratch I copied the php and the database tables from the 'project' > section and renamed 'project' to 'news'. > > > This is working well except for one thing – I get the following error > messages when looking at the detailed news item. This code does not > produce this warning in the project section which is using the same php > code > > > Warning: reset() [function.reset]: Passed variable is not an array or > object in /home/b23aadf/public_html/news/details.php on line 72 > > Warning: Variable passed to each() is not an array or object > in /home/b23aadf/public_html/news/details.php on line 73 > > > The relevant lines are : > put a var_dump($thumbarray); right here and see what $thumbarray is > > 72 reset($thumbsarray); > > 73 while (list($key, $value) = each($thumbsarray)) { > > The site is at www.aadf.co.uk and select 'News'. > > Is anyone able to help resolve this? If you let me know what further > information you require I can provide it. > > > Mike Davies > -- Jim Lucas A: Maybe because some people are too annoyed by top-posting. Q: Why do I not get an answer to my question(s)? A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
From: Shreyas Agasthya on 22 Jun 2010 10:39 Mike, A couple of things that I could understand reading carefully at the error. 1. reset takes an array as the input and perhaps your $thumbsarray is *not *an array? Reset will set the internal pointer to the start of the array. 2. Warning # 2 is very closely related to #1 since you can iterate on an array and not on a variable. 3. Just FYI - You can control the behavior should or not these warnings/notices/errors in your php.ini file. Do a quick google and you should be happy to see the result. Regards, Shreyas On Tue, Jun 22, 2010 at 7:47 PM, Mike Davies <mike(a)integrawebdesign.co.uk>wrote: > Hello, > > This is my first post to this list and I am a novice at php coding. I > can generally follow the code but not good at writing from scratch. > > > I have recently been trying to add to a website which was originally > developed by someone else and is written in php and mysql. I am trying > to add a 'news' section to the site. This would be similar to an > existing 'projects' section so, rather than write it completely from > scratch I copied the php and the database tables from the 'project' > section and renamed 'project' to 'news'. > > > This is working well except for one thing I get the following error > messages when looking at the detailed news item. This code does not > produce this warning in the project section which is using the same php > code > > > Warning: reset() [function.reset]: Passed variable is not an array or > object in /home/b23aadf/public_html/news/details.php on line 72 > > Warning: Variable passed to each() is not an array or object > in /home/b23aadf/public_html/news/details.php on line 73 > > > The relevant lines are : > > > 72 reset($thumbsarray); > > 73 while (list($key, $value) = each($thumbsarray)) { > > The site is at www.aadf.co.uk and select 'News'. > > Is anyone able to help resolve this? If you let me know what further > information you require I can provide it. > > > Mike Davies > > -- > Mike Davies > Integra Web Design, Rhynie, By Huntly, AB54 4LS > 01464 861535 www.integrawebdesign.co.uk > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Regards, Shreyas Agasthya
From: "Daniel P. Brown" on 22 Jun 2010 10:41 On Tue, Jun 22, 2010 at 10:17, Mike Davies <mike(a)integrawebdesign.co.uk> wrote: [snip!] > > Warning: reset() [function.reset]: Passed variable is not an array or > object in /home/b23aadf/public_html/news/details.php on line 72 [snip!] > > Is anyone able to help resolve this? If you let me know what further > information you require I can provide it. Note the first error (quoted herein). That tells you that the variable ($thumbsarray) is not actually an array. How is it being instantiated and defined? -- </Daniel P. Brown> UNADVERTISED DEDICATED SERVER SPECIALS SAME-DAY SETUP Just ask me what we're offering today! daniel.brown(a)parasane.net || danbrown(a)php.net http://www.parasane.net/ || http://www.pilotpig.net/
From: Paul M Foster on 22 Jun 2010 10:55
On Tue, Jun 22, 2010 at 03:17:53PM +0100, Mike Davies wrote: > Hello, > > This is my first post to this list and I am a novice at php coding. I > can generally follow the code but not good at writing from scratch. > > > I have recently been trying to add to a website which was originally > developed by someone else and is written in php and mysql. I am trying > to add a 'news' section to the site. This would be similar to an > existing 'projects' section so, rather than write it completely from > scratch I copied the php and the database tables from the 'project' > section and renamed 'project' to 'news'. > > > This is working well except for one thing – I get the following error > messages when looking at the detailed news item. This code does not > produce this warning in the project section which is using the same php > code > > > Warning: reset() [function.reset]: Passed variable is not an array or > object in /home/b23aadf/public_html/news/details.php on line 72 > > Warning: Variable passed to each() is not an array or object > in /home/b23aadf/public_html/news/details.php on line 73 > > > The relevant lines are : > > > 72 reset($thumbsarray); > > 73 while (list($key, $value) = each($thumbsarray)) { > > The site is at www.aadf.co.uk and select 'News'. > > Is anyone able to help resolve this? If you let me know what further > information you require I can provide it. Well formed question. Thanks for that. I see too many which aren't. I can't say why it's happening, but the $thumbsarray variable isn't getting built the way it should. You can insert a line just before your errors pop up like: <?php echo '$thumbsarray: '; print_r($thumbsarray); ?> or <?php echo '$thumbsarray: '; echo var_dump($thumbsarray); ?> or something similar. This will tell you if the variable is set and what type it has. I'm guessing it's not set. You'll have to look earlier to see where it should be built and isn't. Paul -- Paul M. Foster |