Re: [PHP] Warning messages on web page.
On Tue, 2010-06-22 at 10:41 -0400, Daniel P. Brown wrote: On Tue, Jun 22, 2010 at 10:17, Mike Davies m...@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? The only earlier reference to $thumbsarray is in the first lines of the file : ?php mysql_select_db($database_general, $general); $query_details = SELECT * FROM news WHERE news_id = '$_GET[id]'; $details = mysql_query($query_details, $general) or die(mysql_error()); $row_details = mysql_fetch_assoc($details); $totalRows_details = mysql_num_rows($details); mysql_select_db($database_general, $general); $query_thumbs = SELECT * FROM news_thumbs; $thumbs = mysql_query($query_thumbs, $general) or die(mysql_error()); $totalRows_thumbs = mysql_num_rows($thumbs); $i = 1; while ($row_thumbs = mysql_fetch_assoc($thumbs)){ $thumbsarray[$i] = $row_thumbs; $i++; } //print_r($thumbsarray); ? This is exactly the same as the code which is working for the 'projects' pages. Mike -- Mike Davies Integra Web Design, Rhynie, By Huntly, AB54 4LS 01464 861535www.integrawebdesign.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Warning messages on web page.
Mike, Little weird. I executed the same lines of code against my sample database and did not got any warning. You might want to send the code for projects and news to do any comparison? *[I will silently wait for the PHP demi-gods (the Ashleys, the Pauls et al) at hover their vigilant eyes on your lines .:) ]* Regards, Shreyas On Wed, Jun 23, 2010 at 2:48 PM, Mike Davies m...@integrawebdesign.co.ukwrote: The only earlier reference to $thumbsarray is in the first lines of the file : ?php mysql_select_db($database_general, $general); $query_details = SELECT * FROM news WHERE news_id = '$_GET[id]'; $details = mysql_query($query_details, $general) or die(mysql_error()); $row_details = mysql_fetch_assoc($details); $totalRows_details = mysql_num_rows($details); mysql_select_db($database_general, $general); $query_thumbs = SELECT * FROM news_thumbs; $thumbs = mysql_query($query_thumbs, $general) or die(mysql_error()); $totalRows_thumbs = mysql_num_rows($thumbs); $i = 1; while ($row_thumbs = mysql_fetch_assoc($thumbs)){ $thumbsarray[$i] = $row_thumbs; $i++; } //print_r($thumbsarray); ? This is exactly the same as the code which is working for the 'projects' pages. Mike -- Mike Davies Integra Web Design, Rhynie, By Huntly, AB54 4LS 01464 861535www.integrawebdesign.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Regards, Shreyas Agasthya
Re: [PHP] Warning messages on web page.
On Wed, 2010-06-23 at 15:55 +0530, Shreyas Agasthya wrote: Mike, Little weird. I executed the same lines of code against my sample database and did not got any warning. You might want to send the code for projects and news to do any comparison? *[I will silently wait for the PHP demi-gods (the Ashleys, the Pauls et al) at hover their vigilant eyes on your lines .:) ]* Regards, Shreyas On Wed, Jun 23, 2010 at 2:48 PM, Mike Davies m...@integrawebdesign.co.ukwrote: The only earlier reference to $thumbsarray is in the first lines of the file : ?php mysql_select_db($database_general, $general); $query_details = SELECT * FROM news WHERE news_id = '$_GET[id]'; $details = mysql_query($query_details, $general) or die(mysql_error()); $row_details = mysql_fetch_assoc($details); $totalRows_details = mysql_num_rows($details); mysql_select_db($database_general, $general); $query_thumbs = SELECT * FROM news_thumbs; $thumbs = mysql_query($query_thumbs, $general) or die(mysql_error()); $totalRows_thumbs = mysql_num_rows($thumbs); $i = 1; while ($row_thumbs = mysql_fetch_assoc($thumbs)){ $thumbsarray[$i] = $row_thumbs; $i++; } //print_r($thumbsarray); ? This is exactly the same as the code which is working for the 'projects' pages. Mike -- Mike Davies Integra Web Design, Rhynie, By Huntly, AB54 4LS 01464 861535www.integrawebdesign.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php If you didn't get any warnings on your test machine, it might just be because of a different error reporting being set up. As for the local test, did it work as expected? If so, and the code hasn't changed, then it might be the actual tables in the database. If there are no rows returned where you expected some, and the code expects rows as an array, then it could be the cause of the problem. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Warning messages on web page.
Hold everything, Mike! On Wed, Jun 23, 2010 at 05:18, Mike Davies m...@integrawebdesign.co.uk wrote: [snip!] ?php mysql_select_db($database_general, $general); $query_details = SELECT * FROM news WHERE news_id = '$_GET[id]'; /** * Above line is placed here so that we can be easily, * deliberately, and permanently destroyed. Of course, * I suppose we *could* avoid that by sanitizing the input. * Perhaps mysql_real_escape_string() or something */ $details = mysql_query($query_details, $general) or die(mysql_error()); $row_details = mysql_fetch_assoc($details); $totalRows_details = mysql_num_rows($details); mysql_select_db($database_general, $general); // You don't need to reconnect to the database between queries. // Since you're using the same here as above, the same link is fine. $query_thumbs = SELECT * FROM news_thumbs; $thumbs = mysql_query($query_thumbs, $general) or die(mysql_error()); // You don't need to tell mysql_query() which database to use every time // either, when using the same database for queries. $totalRows_thumbs = mysql_num_rows($thumbs); // Doesn't look like you use this --- at least in this code snippet. Necessary? $i = 1; // I'd lose the above line as well. You'll see why in a second /** REPLACE THIS: while ($row_thumbs = mysql_fetch_assoc($thumbs)){ $thumbsarray[$i] = $row_thumbs; $i++; } **/ // WITH THIS: while($row_thumbs = mysql_fetch_assoc($thumbs)) { $thumbsarray[] = $row_thumbs; } //print_r($thumbsarray); ? This is exactly the same as the code which is working for the 'projects' pages. Okay. On the database to which you're connecting, use phpMyAdmin, the MySQL CLI, or something other than this and run the following query: SELECT * FROM news_thumbs; Is anything returned? -- /Daniel P. Brown UNADVERTISED DEDICATED SERVER SPECIALS SAME-DAY SETUP Just ask me what we're offering today! daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Warning messages on web page.
On Wed, 2010-06-23 at 09:09 -0400, Daniel Brown wrote: Hold everything, Mike! On Wed, Jun 23, 2010 at 05:18, Mike Davies m...@integrawebdesign.co.uk wrote: [snip!] ?php mysql_select_db($database_general, $general); $query_details = SELECT * FROM news WHERE news_id = '$_GET[id]'; /** * Above line is placed here so that we can be easily, * deliberately, and permanently destroyed. Of course, * I suppose we *could* avoid that by sanitizing the input. * Perhaps mysql_real_escape_string() or something */ $details = mysql_query($query_details, $general) or die(mysql_error()); $row_details = mysql_fetch_assoc($details); $totalRows_details = mysql_num_rows($details); mysql_select_db($database_general, $general); // You don't need to reconnect to the database between queries. // Since you're using the same here as above, the same link is fine. $query_thumbs = SELECT * FROM news_thumbs; $thumbs = mysql_query($query_thumbs, $general) or die(mysql_error()); // You don't need to tell mysql_query() which database to use every time // either, when using the same database for queries. $totalRows_thumbs = mysql_num_rows($thumbs); // Doesn't look like you use this --- at least in this code snippet. Necessary? $i = 1; // I'd lose the above line as well. You'll see why in a second /** REPLACE THIS: while ($row_thumbs = mysql_fetch_assoc($thumbs)){ $thumbsarray[$i] = $row_thumbs; $i++; } **/ // WITH THIS: while($row_thumbs = mysql_fetch_assoc($thumbs)) { $thumbsarray[] = $row_thumbs; } //print_r($thumbsarray); ? This is exactly the same as the code which is working for the 'projects' pages. Okay. On the database to which you're connecting, use phpMyAdmin, the MySQL CLI, or something other than this and run the following query: SELECT * FROM news_thumbs; Is anything returned? Nothing is returned for SELECT query as there is nothing in the table as yet. Perhaps this is the problem. Typically all projects would have an associated thumb image but all news items may not. Perhaps a thumb image is necessary to stop this warning? Should I change the code to allow for there being no thumb image, if so can you suggest how I might modify it? Thanks to everyone who has responded, it has been most useful. regards, Mike -- Mike Davies Integra Web Design, Rhynie, By Huntly, AB54 4LS 01464 861535www.integrawebdesign.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Warning messages on web page.
On Wed, 2010-06-23 at 16:14 +0100, Mike Davies wrote: On Wed, 2010-06-23 at 09:09 -0400, Daniel Brown wrote: Hold everything, Mike! On Wed, Jun 23, 2010 at 05:18, Mike Davies m...@integrawebdesign.co.uk wrote: [snip!] ?php mysql_select_db($database_general, $general); $query_details = SELECT * FROM news WHERE news_id = '$_GET[id]'; /** * Above line is placed here so that we can be easily, * deliberately, and permanently destroyed. Of course, * I suppose we *could* avoid that by sanitizing the input. * Perhaps mysql_real_escape_string() or something */ $details = mysql_query($query_details, $general) or die(mysql_error()); $row_details = mysql_fetch_assoc($details); $totalRows_details = mysql_num_rows($details); mysql_select_db($database_general, $general); // You don't need to reconnect to the database between queries. // Since you're using the same here as above, the same link is fine. $query_thumbs = SELECT * FROM news_thumbs; $thumbs = mysql_query($query_thumbs, $general) or die(mysql_error()); // You don't need to tell mysql_query() which database to use every time // either, when using the same database for queries. $totalRows_thumbs = mysql_num_rows($thumbs); // Doesn't look like you use this --- at least in this code snippet. Necessary? $i = 1; // I'd lose the above line as well. You'll see why in a second /** REPLACE THIS: while ($row_thumbs = mysql_fetch_assoc($thumbs)){ $thumbsarray[$i] = $row_thumbs; $i++; } **/ // WITH THIS: while($row_thumbs = mysql_fetch_assoc($thumbs)) { $thumbsarray[] = $row_thumbs; } //print_r($thumbsarray); ? This is exactly the same as the code which is working for the 'projects' pages. Okay. On the database to which you're connecting, use phpMyAdmin, the MySQL CLI, or something other than this and run the following query: SELECT * FROM news_thumbs; Is anything returned? Nothing is returned for SELECT query as there is nothing in the table as yet. Perhaps this is the problem. Typically all projects would have an associated thumb image but all news items may not. Perhaps a thumb image is necessary to stop this warning? Should I change the code to allow for there being no thumb image, if so can you suggest how I might modify it? Thanks to everyone who has responded, it has been most useful. regards, Mike -- Mike Davies Integra Web Design, Rhynie, By Huntly, AB54 4LS 01464 861535www.integrawebdesign.co.uk If you haven't in your code, then make sure you define $thumbsarray as an array before you attempt to use it in the loop. This will have no effect where rows are returned, but it will ensure an empty array exists if your code expects it and there is no data in the database to populate it. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Warning messages on web page.
On Wed, Jun 23, 2010 at 11:14, Mike Davies m...@integrawebdesign.co.uk wrote: Nothing is returned for SELECT query as there is nothing in the table as yet. Perhaps this is the problem. Typically all projects would have an associated thumb image but all news items may not. Perhaps a thumb image is necessary to stop this warning? Should I change the code to allow for there being no thumb image, if so can you suggest how I might modify it? With no rows returned, there's no array. The while() loop doesn't even trigger there. You could either add some dummy data, populate the rows, or adjust the code like so: ?php if (isset($thumbsarray) is_array($thumbsarray)) { while (list($key, $value) = each($thumbsarray)) { // ... } } else { // There are no thumbs. Oh, my God, the horror! No thumbs! } ? -- /Daniel P. Brown UNADVERTISED DEDICATED SERVER SPECIALS SAME-DAY SETUP Just ask me what we're offering today! daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Warning messages on web page.
On Wed, 2010-06-23 at 16:22 +0100, Ashley Sheridan wrote: On Wed, 2010-06-23 at 16:14 +0100, Mike Davies wrote: If you haven't in your code, then make sure you define $thumbsarray as an array before you attempt to use it in the loop. This will have no effect where rows are returned, but it will ensure an empty array exists if your code expects it and there is no data in the database to populate it. Thanks, Ash http://www.ashleysheridan.co.uk Thanks Ash and to everyone else. I added : $thumbsarray=array() above the first instance and the warning no longer appears. Hopefully nothing else will be affected. Many thanks for all your time. regards, Mike -- Mike Davies Integra Web Design, Rhynie, By Huntly, AB54 4LS 01464 861535www.integrawebdesign.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Warning messages on web page.
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 861535www.integrawebdesign.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Warning messages on web page.
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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Warning messages on web page.
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 m...@integrawebdesign.co.ukwrote: 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 861535www.integrawebdesign.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Regards, Shreyas Agasthya
Re: [PHP] Warning messages on web page.
On Tue, Jun 22, 2010 at 10:17, Mike Davies m...@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.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Warning messages on web page.
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php