name.oleg Posted April 12, 2009 Share Posted April 12, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/153689-how-to-write-array-in-mysql/ Share on other sites More sharing options...
Carth Posted April 15, 2009 Share Posted April 15, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153689-how-to-write-array-in-mysql/#findComment-810758 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.