muraduk Posted July 25, 2010 Posted July 25, 2010 Hi I am getting an error on the home page of Warning: Illegal string offset: -1 in /home/healthca/public_html/includes/modules/new_products.php on line 42 ================================================= $sql = 'SELECT `products_description` FROM `products_description` WHERE products_id ='.$new_products['products_id'].' && language_id='.(int)$languages_id; $description_query = tep_db_query($sql); $description = mysql_fetch_array($description_query, MYSQL_ASSOC); $description['products_description'] = substr($description['products_description'], 0, 65); $desc_len = strlen($description['products_description']); $description['products_description'][$desc_len-1] = '.'; $description['products_description'][$desc_len-2] = '.'; $description['products_description'][$desc_len-3] = '.';========================================================================== The last line is line 42.... does anyone know what this coding dictates... Thanks...in advance
MrPhil Posted July 25, 2010 Posted July 25, 2010 Ugh. Where did that code come from? It appears to be heavily modified, and whoever did it botched the job. First of all, I suspect that line "42" is two lines up. $desc_len has a value of 0 (or null, or some non-numeric value). I presume that the intent is to take the first 65 characters of the "product_description" text (does that work OK?). Then you're replacing the last three characters with "...". I would change $description['products_description'] = substr($description['products_description'], 0, 65); $desc_len = strlen($description['products_description']); $description['products_description'][$desc_len-1] = '.'; $description['products_description'][$desc_len-2] = '.'; $description['products_description'][$desc_len-3] = '.'; to $description['products_description'] = substr($description['products_description'], 0, 62) . '...'; There are other ways it could be done (including using {$desc_len-1} instead of square brackets), but that's probably the easiest. Note that there is no check to see if the description is already short enough that it doesn't need the ellipsis.
muraduk Posted July 25, 2010 Author Posted July 25, 2010 Hi thats great....it worked a treat... Thanks..again,,
Recommended Posts
Archived
This topic is now archived and is closed to further replies.