Wednesday, 15 January 2014

Use PHP to copy partial MySQL column data to another -


I have the "extra images" column in my myqql db, and I (still unsuccessful) just trying to copy The first URL in the second column as "Main Image" is for example

For example:

  http://website.com/img1.jpg,http:/ /website.com/img2.jpg, http://website.com/img3.jpg.etc ..   

There is no quotation mark around these images, and via DB feed Is updated automatically, so just update manually from each question The town.

I have some PHP code:

  $ query5 = "Select COL_66 FROM tbl_name"; $ Result6 = mysql_query ($ query5); If (! $ 6 result) {echo 'question 5 fail:' mysql_error (); Go out; } $ Row2 = mysql_fetch_row ($ result6);   

I was trying to use

  $ picture = implode (",", $ row2); $ Image [0];   

And then I tried

  $ picture = explosion (",", $ line 2); $ Image [0]; The return is for the explosion:   ex>  Warning: Explosion () believes that because the parameter is 2 string ... ...   

I am assuming this because there is no quotation mark around the IMG URL (?)

Am I doing something wrong? Is it anything to do with quotation marks?

Thanks for reading & amp; Any help

You're using it to get an array of strings in a string.

You need to contradict ..., which takes a string and divides it into an array.

You will need a loop through your result set, like this:

  while ($ row2 = $ mysql_fetch_row ($ result6)) {// you need The column query returned by $ photo = explosion before handling the column (',', $ line 2 [0]); $ Image [0]; // or list ($ picture) = explosion (',', $ line 2 [0]); $ Picture; }   

As said in the @zerkms question comment, you should store it differently. It looks like one-to-one relationship, so you should put these URLs in a separate table. Something like this:

  + ------------- + --------------------- - ------- + --------- + | MainTable IDE | Url | Primary | + ------------- + ----------------------------- + ----- ---- + | 1 | Http://website.com/img1.jpg | 1 | | 1 | Http://website.com/img2.jpg | 0 | | 1 | Http: //website.com/img3.jpg | 0 | + ------------- + ----------------------------- + ----- ---- +   

The main table id is a foreign key for your main table and primary is a bit field that indicates That's what your "main image" is called normalization .

No comments:

Post a Comment