foreach/sql errors when creating CCK fields
nicholasThompson - November 7, 2008 - 22:56
| Project: | Relevant Content |
| Version: | 5.x-1.3 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | nicholasThompson |
| Status: | patch (to be ported) |
Description
Need to investigate why CCK is throwing foreach() errors and/or SQL errors when adding new or existing fields to content types....

#1
I'm also have the same error in 5.x version. This error occurs on the page that is attempting to display the CCK field. Let me know if I can assist further.
# warning: Invalid argument supplied for foreach() in /chroot/home/mydir/mydomain/html/sites/all/modules/relevant_content/relevant_content_cck/relevant_content_cck.module on line 99.# warning: Invalid argument supplied for foreach() in /chroot/home/mydir/mydomain/html/sites/all/modules/relevant_content/relevant_content_cck/relevant_content_cck.module on line 211
#2
Interesting...
Although I think this is slightly different. My errors were in CCK's content.module whereas yours are inside my module.
Cheers for bringing this up though!
#3
I'm having the exact same issue, in that the error is coming from the Relevant Content module cck function.
One of my users is reporting the issue and it seems it might be happening from using the preview without saving and then trying to add content to another cck field. Although I am unable to duplicate it.
On the other hand, to fix it, I simply remove all of the entries my user has placed in the taxonomy field and enter one single term into the taxonomy field (I require at least one entry) and save. At that point the problem goes away and I can do anything I want to the page.
#4
I'm seeing foreach errors as well but for line 226 of the relevant content CCK module. Subscribing.
Update: I noticed that I only get the foreach error when the relevant content field is enabled to display one the teaser which I'm displaying in a view I created. When I click through to the node there are no errors. For the moment I have hidden the relevant content field from the teaser view which is at http://learnbythedrop.com/drops.
Update 2: I have narrowed down the instances when the error occurs even further. It appears that the error is being thrown when a node is displayed that has no relevant posts associated with it. I'm seeing the error thrown on the post at http://learnbythedrop.com/drop/70. It just so happens that the teaser for the same post was shown in the view that I reference earlier.
#5
Hi there, I had the same error as nicholasThompson, in cck instead of relevant content.
warning: Invalid argument supplied for foreach() in D:\xampp\htdocs\demo\sites\all\modules\cck\content.module on line 1270. This error repeats for each return results.
I notice this only happens when I tried to display as teasers. Where'as when displaying as full nodes, I get a whole "page not available/The connection to the server was reset while the page was loading" error. It working fine when displaying as title and title link.
Drupal 6.6
CCK 2.1 and latest dev (2008-Dec-04)
Relevant content 6.14 and latest dev (2008-Nov-07)
#6
Possibly related to #346576: hook_content_is_empty() is not implemented
#7
Hi there,
I was getting the following error:
warning: Invalid argument supplied for foreach() in /home/jack/workspace/peckhampower/trunk/sites/all/modules/relevant_content/relevant_content_cck/relevant_content_cck.module on line 228.As awakenedvoice mentioned in comment #4, it seems that the error is generated when a node has a unique tag (i.e. a tag which is only applied to the current node). I did a bit of tinkering and it turns out that the variable
$element['items']['#item']is null when the error occurs. So I've added a quickifstatement to test if the$element['items']['#item']variable is set before continuing with theforeachstatement.This is what lines 227 to 230 in
relevant_content_cck.modulecurrently looks like in version 6.x-1.4 of the module:<?phpforeach ($element['items']['#item'] as $delta => $item) {
$items_output .= '<div class="field-item '. ($count % 2 ? 'odd' : 'even') .'">'. theme('relevant_content_cck_field_format_'. $format, $item) .'</div>';
$count++;
}
?>
I have replaced the code above with the following code:
<?phpif ($element['items']['#item']) {
foreach ($element['items']['#item'] as $delta => $item) {
$items_output .= '<div class="field-item '. ($count % 2 ? 'odd' : 'even') .'">'. theme('relevant_content_cck_field_format_'. $format, $item) .'</div>';
$count++;
}
}
?>
i.e. I've simply wrapped the
foreachloop in anifstatement.My modification seems to have fixed the problem for me. I haven't yet noticed any side-effects.
#8
I have been activied All CCK MODUL 28 Feb 2009, here .. is my module
#9
Same error, different line number, not sure if it makes a difference.
This is with D6.10 and latest CCK
warning: Invalid argument supplied for foreach() in /sites/all/modules/relevant_content/relevant_content_cck/relevant_content_cck.module on line 226.
is the full path of where drupal is installed, I just edited it for my own security.
If I get the error on a node, then I get no relevant content. If I get the error in the admin screens somewhere, then most things still work, I just see this error in red. This is definitely a bug.
#10
I tried wrapping the foreach in the if statement provided above and that got rid of the error. I recommend that patch.
#11
Hi,
I'm getting those errors with version 5.x-1.3:
Invalid argument supplied for foreach() in /var/www/drupal/sites/all/modules/relevant_content/relevant_content_cck/relevant_content_cck.module in Zeile 211.Has someone already tried applying the patch to the D5 version?
Thanks & greetings, -asb
#12
I see the error on line 226 (as reported in #4) using CCK 6.x-2.x-dev built on 2009-04-24
warning: Invalid argument supplied for foreach() in /var/www/drupal/sites/all/modules/relevant_content/relevant_content_cck/relevant_content_cck.module on line 226.#13
The bug is still there, even after the patch as described in #7.
If I select the field output as title or full node, it works, if I select to display it as teaser, it's broken.
#14
Similar/duplicate issues: 354459 (D5) & 451726 (D6).
Greetings, -asb
#15
It didn't work for me either, but I got it working with this:
if ($element['items']['#item'] != "") {.
.
instead of:
if ($element['items']['#item']) {.
.
This hasn't been extensively tested, but PHP booleans don't always work out the way you expect them to.
#16
i got these errors when activating both
warning: Invalid argument supplied for foreach() in path_to_drupal_root_directory\includes\form.inc on line 1200.
warning: Invalid argument supplied for foreach() in path_to_drupal_root_directory\includes\form.inc on line 1200.
i added a field to a cck type and all runs fine, but when i tryed to add the existing relevant content field to another cck field i get this one
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') SELECT vid, nid, FROM content_type_investmentproperty' at line 1 query: INSERT INTO content_field_relcontent (vid, nid, ) SELECT vid, nid, FROM content_type_investmentproperty in path_to_drupal_root_directory\sites\all\modules\cck\includes\content.admin.inc on line 1527.
i´m using the newest D6 version
#17
and another one when adding a existing "relevant content" to a cck
user warning: Unknown column 'delta' in 'where clause' query: DELETE FROM content_field_relcontent WHERE delta >= 1 in path_to_drupal_root_directory\sites\all\modules\cck\includes\content.admin.inc on line 1492.
#18
yup same here:
Invalid argument supplied for foreach() in /var/www/html/{foo}/relevant_content/relevant_content_cck/relevant_content_cck.module on line 226.
gonna wrap in an IF statement as suggested here:
http://drupal.org/node/331625#comment-1204192
#19
I also used the patch, seems to be working just fine now.
#20
Here is a simple patch for 5.x-1.3. It may work for other versions. I wrapped each foreach in an if (!empty($items)) statement.
Works for me.
Hope this makes it into the code.
#21
Hi,
thank you the patch; with "-p0" option the patch applies cleanly on D5.
On D6 it fails ("Hunk #1 FAILED at 96. ... Hunk #2 FAILED at 208")
Greetings, -asb
#22
Hi again,
any progress on this issue?
Thanks & greetings, -asb