Welcome Guest, Not a member yet? Register   Sign In
Images not loading, adding to the end
#1

[eluser]JacobRyan[/eluser]
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

[eluser]Cristian Gilè[/eluser]
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:

Code:
items => (id|.........)

additional_images => (id|file_name)

item_additional_image => (id|item_id|addition_image_id)
#3

[eluser]JacobRyan[/eluser]
[quote author="Cristian Gilè" date="1294273571"]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:

Code:
items => (id|.........)

additional_images => (id|file_name)

item_additional_image => (id|item_id|addition_image_id)
[/quote]

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

[eluser]Cristian Gilè[/eluser]
Once you have read the additional_images field explode its content.

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

$images is an array.
#5

[eluser]JacobRyan[/eluser]
[quote author="Cristian Gilè" date="1294274460"]Once you have read the additional_images field explode its content.

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

$images is an array.[/quote]

http://kbctoolsandmachinery.com/product/...-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/...-269-006-N the additional images work.
#6

[eluser]Cristian Gilè[/eluser]
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

[eluser]JacobRyan[/eluser]
[quote author="Cristian Gilè" date="1294278844"]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.[/quote]

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

[eluser]Cristian Gilè[/eluser]
Do you use phpmyadmin to insert data in db?
#9

[eluser]JacobRyan[/eluser]
Yes, I use phpmyadmin.
#10

[eluser]Cristian Gilè[/eluser]
After you have inserted by hand images file name, launch the following query in phpmyadmin clicking on the SQL tab:

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

additional_images is the field name.




Theme © iAndrew 2016 - Forum software by © MyBB