DBookatay Posted April 6, 2007 Share Posted April 6, 2007 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) Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 6, 2007 Share Posted April 6, 2007 We need more information. How is the variable $row being set? How is the variable $value being set? Ken Quote Link to comment Share on other sites More sharing options...
DBookatay Posted April 6, 2007 Author Share Posted April 6, 2007 <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++; } Quote Link to comment Share on other sites More sharing options...
obsidian Posted April 6, 2007 Share Posted April 6, 2007 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! Quote Link to comment Share on other sites More sharing options...
DBookatay Posted April 6, 2007 Author Share Posted April 6, 2007 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! Quote Link to comment Share on other sites More sharing options...
obsidian Posted April 6, 2007 Share Posted April 6, 2007 How do I solve this problem? I am still in the "learning phase" of php! I added one line to your code in the code I posted above that should fix this issue for you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.