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)

<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++;

}

 

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!

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.