Jump to content

how to write array in mysql?


name.oleg

Recommended Posts

i have a table 'models':

id, mark, model, description, language

 

and a table 'carimages':

id, mark, model, images

 

in the field models.description there is a description of a car and also a html <img> tags:

<a href='images/big_images/2102_1.JPG'><img src='images/big_images/2102_1.JPG' alt='2102' /></a>

<a href='images/big_images/2102_2.JPG'><img src='images/big_images/2102_2.JPG' alt='2102' /></a>

<a href='images/big_images/2102_3.JPG'><img src='images/big_images/2102_3.JPG' alt='2102' /></a>

<a href='images/big_images/2102_4.JPG'><img src='images/big_images/2102_4.JPG' alt='2102' /></a>

<a href='images/big_images/2102_5.JPG'><img src='images/big_images/2102_5.JPG' alt='2102' /></a>

<a href='images/big_images/2102_6.JPG'><img src='images/big_images/2102_6.JPG' alt='2102' /></a>

 

i need to find using reg.ex. those <img> tags in models.description field to write them in carimages.images

 

 

$h= mysql_query("select * from models") or die(mysql_error());

$pat="|<img[\s]*src=\'images\/big\_images\/([\_a-zA-Z\.0-9]+\.[a-zA-Z]{3,4})\'[\s]*alt=\'([\sa-zA-Z0-9]+)\'[\s]*\/>|isU";


while(list($id2, $cm2, $cmo2, $descr,$lang2) = mysql_fetch_array($h)){
$descr = str_replace('"', "'", $descr);
preg_match_all($pat, $descr, $myout);
//$che=implode("",$myout[0]);
$che = serialize($myout[0]);
mysql_query("insert into carimages values(0, '$cm2', '$cmo2', '$che')");
}

if i understand correctly i have to convert array in a string:

$che=implode("",$myout[0]);

or

$che = serialize($myout[0]);

 

right?

 

Array $myout[0] is not empty, reg.ex. works correctly but it writes nothing in carimages.images

 

What am i doing wrong?

Link to comment
Share on other sites

As far as I'm aware, $myout is an array of strings, so $myout[0] is a string, therefore no need for serialize() or implode().

 

I don't know if there are other problems.

 

It might be better not to store HTML in the database like this, nor duplicate data - it needs normalising. But that's another matter and shouldn't prevent it from working.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.