Jump to content

Warning: implode() [function.implode]: Bad arguments


DBookatay

Recommended Posts

Can someone tell me what I wrong with this code:

unset ($features);
foreach ($row as $feature => $value) {
if (substr($feature, 0,== "feature_") {
   if ($feature == "feature_4w") {if ($value == "yes") {$features[] = "4 x 4";}}
   if ($feature == "feature_ac") {if ($value == "yes") {$features[] = "AC";}}
   if ($feature == "feature_pw") {if ($value == "yes") {$features[] = "Power Windows";}}
   if ($feature == "feature_pl") {if ($value == "yes") {$features[] = "Power Locks";}}
   if ($feature == "feature_pm") {if ($value == "yes") {$features[] = "Power Mirrors";}}
   if ($feature == "feature_cc") {if ($value == "yes") {$features[] = "Cruise";}}
   if ($feature == "feature_sr") {if ($value == "yes") {$features[] = "Sunroof";}}
   if ($feature == "feature_ls") {if ($value == "yes") {$features[] = "Leather";}}
   if ($feature == "feature_aw") {if ($value == "yes") {$features[] = "Alloys";}}
   if ($feature == "feature_sp") {if ($value == "yes") {$features[] = "Plow";}}
}
}
$features_string=implode(", ",$features);

 

This code used to work perfectly, but after switching hosting companies I am getting certain errors on my site that never used to be there. One of which is "Warning: implode() [function.implode]: Bad arguments. in /home/.phillipina/dbookatay/carcityofdanbury.com/inventory_search.php on line 238"

 

(The url where the erors are is: http://www.carcityofdanbury.com/inventory_search.php?category=foreign&page=2)

Link to comment
Share on other sites

<table class=\"$class\" onmouseout=\"this.className='$class'\" onmouseover=\"this.className='over'\" onClick=\"document.location.href='inventory_view.php?stock={$row['stock']}'\">

<tr>

<td class=\"thumb\" rowspan=\"2\">$image</td>

<td class=\"vehicle\">$vehicle</td>

<td class=\"miles\">$mi</td>

<td class=\"eng\">$engine</td>

<td class=\"trans\">$trans</td>

<td class=\"body\">$body</td>

<td class=\"asking\">$asking</td>

</tr>

<tr><td class=\"feats\" colspan=\"6\">{$fuel} {$drive} {$features_string}</td></tr>

</table>\n";

$row_count++;

}

 

Link to comment
Share on other sites

You run unset() on your $features variable, and then you're only re-instantiating the variable if one of the conditions is met. Finally, you are assuming that the variable has been set when you use implode() on it. You need to unset it and then immediately reassign it as an empty array:

<?php
unset($features);
$features = array();
if (/* your checks in here */) {

}

$feature_string = implode(', ', $features);
?>

 

The way you have it currently, the error will be thrown on a car where none of your feature conditions have been met. Most likely, you moved from a server with error suppression turned on to one where it is not.

 

Good luck!

Link to comment
Share on other sites

The way you have it currently, the error will be thrown on a car where none of your feature conditions have been met. Most likely, you moved from a server with error suppression turned on to one where it is not.

 

Good luck!

 

How do I solve this problem? I am still in the "learning phase" of php!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.