ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Images not loading, adding to the end

January 05, 2011 2:05pm

Subscribe [2]
  • #1 / Jan 05, 2011 2:05pm

    JacobRyan

    7 posts

    To be honest I’ve never fully used CodeIgniter my knowledge is loosely based around what I’ve learned from making very tiny updates to our companies website, mainly on the database end. So I’m unsure if this is a CI problem or the problem lies somewhere else.

    In our database we call a field named additional_images, and within that field there can be anywhere from one additional images to about four or five. All current items that are in the database are fine, but I recently had to add some new product manually, as I’m only provided with an excel file and I’m unsure how to make it a workable SQL. So I figured I’d insert the rows manually. The problem that’s happening is when I write in the additional images (that are stored in an asset folder that the product_view calls it’s adding a (percent)0D after the .jpg extension causing the image to not load.

    When I write the file names into the database, I did as the others are done and just wrote:
    Image1.jpg
    Image2.jpg
    Image3.jpg

    Images 1 and 2 will not load because of the
    (which I’m assuming is a carriage return?), but since their is no return after Image3.jpg it’ll load. Is there anyway I can fix this problem?

  • #2 / Jan 05, 2011 2:26pm

    Cristian Gilè

    377 posts

    If I haven’t misunderstood, you have a field, additional_images, in the items table, that can contain one or multiple file names.

    For example, for item A addiotional_images can contain (image1.jpg\nimage2.jpg\nimage3.jpg). Right?

    This not a good approach. I suggest you to keep a separate table for additional_images with id and file_name fields, and a separate table to match items and additional_images with id_item and id_additional_image fields.

    Here, a minimal ER:

    items => (id|.........)
    
    additional_images => (id|file_name)
    
    item_additional_image => (id|item_id|addition_image_id)
  • #3 / Jan 05, 2011 2:29pm

    JacobRyan

    7 posts

    If I haven’t misunderstood, you have a field, additional_images, in the items table, that can contain one or multiple file names.

    For example, for item A addiotional_images can contain (image1.jpg\nimage2.jpg\nimage3.jpg). Right?

    This not a good approach. I suggest you to keep a separate table for additional_images with id and file_name fields, and a separate table to match items and additional_images with id_item and id_additional_image fields.

    Here, a minimal ER:

    items => (id|.........)
    
    additional_images => (id|file_name)
    
    item_additional_image => (id|item_id|addition_image_id)

    Sorry I didnt realize that it would actually make a carriage return, it’s adding (percent sign)0D after the .jpg extension, and I can’t really take up the process of editing anything in the database as I’ll admit I’m not knowledgeable enough to do so. The idea when the site was designed by the company we hired was that it’d be easy enough to update without having to change code (wishful thinking). What happened was we took the website back in house after a falling out between our manager and the creators of the website. Whom would take the excel file given to them by one of our guys, and convert it to SQL and inject it without problem.

  • #4 / Jan 05, 2011 2:41pm

    Cristian Gilè

    377 posts

    Once you have read the additional_images field explode its content.

    $images = explode('\r',$additional_images_content);

    $images is an array.

  • #5 / Jan 05, 2011 3:17pm

    JacobRyan

    7 posts

    Once you have read the additional_images field explode its content.

    $images = explode('\r',$additional_images_content);

    $images is an array.

    http://kbctoolsandmachinery.com/product/show/6-273-067-N

    There is an example, if you hover over one of the broken images you’ll see.

    Where as http://kbctoolsandmachinery.com/product/show/6-269-006-N the additional images work.

  • #6 / Jan 05, 2011 3:54pm

    Cristian Gilè

    377 posts

    Have you tried to explode the content of the additional_images field ?

    The % 0D at the end of the images file name is a carriage return (\r). The explode function returns an array of strings (images file name), each of which is a substring of the addiotional_images content field formed by splitting it on boundaries formed by the \r delimiter.

    Your addiotinal_images field content is like this:

    image1.jpg% 0D
    image2.jpg% 0D
    image3.jpg% 0D
    image4.jpg

    after explode it, the result array contains:

    image1.jpg
    image2.jpg
    image3.jpg
    image4.jpg

    without the carriage return.

    Please, paste here a reduction of your controller and your model.

    If possible, save images in asset folder without spaces in the file name.

  • #7 / Jan 05, 2011 4:27pm

    JacobRyan

    7 posts

    Have you tried to explode the content of the additional_images field ?

    The % 0D at the end of the images file name is a carriage return (\r). The explode function returns an array of strings (images file name), each of which is a substring of the addiotional_images content field formed by splitting it on boundaries formed by the \r delimiter.

    Your addiotinal_images field content is like this:

    image1.jpg% 0D
    image2.jpg% 0D
    image3.jpg% 0D
    image4.jpg

    after explode it, the result array contains:

    image1.jpg
    image2.jpg
    image3.jpg
    image4.jpg

    without the carriage return.

    Please, paste here a reduction of your controller and your model.

    If possible, save images in asset folder without spaces in the file name.

    I’m not quite sure what you’re asking for. I do see in my SQL dump that it’s adding a carriage return after the new items I added in by hand.

  • #8 / Jan 05, 2011 5:29pm

    Cristian Gilè

    377 posts

    Do you use phpmyadmin to insert data in db?

  • #9 / Jan 05, 2011 5:32pm

    JacobRyan

    7 posts

    Yes, I use phpmyadmin.

  • #10 / Jan 06, 2011 5:30am

    Cristian Gilè

    377 posts

    After you have inserted by hand images file name, launch the following query in phpmyadmin clicking on the SQL tab:

    UPDATE yourtablename SET additional_images = REPLACE(additional_images, '\r\n', '\n')

    additional_images is the field name.

  • #11 / Jan 06, 2011 6:52am

    JacobRyan

    7 posts

    You sir, are the man. Last night before you posted this I realized I’d have to run an SQL Query, thank you so much. I got this saved for future reference.

  • #12 / Jan 06, 2011 8:07am

    Cristian Gilè

    377 posts

    I’m glad to hear that the issue has been solved.

    Cheers

    Cristian Gilè

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases