mysql - Putting several values into one column but different rows in php -


i have 3 variables: $title, $pubdate , $link

and in variables, there several values this:

$title = aa, bb, cc, dd, ee, ff $pubdate = aa, bb, cc, dd, ee, ff $link = aa, bb, cc, dd, ee, ff 

like this. have table columns (title, pubdate , link). have tried:

$sql = "insert ytable (title, pubdate, link) values ('$title', '$pubdate', '$link')"; mysql_query($sql,$db_con); 

although no error pops up, not perform want do. puts of values(aa, bb, cc, dd, ee, ff) 1 column(title) , 1 row(id = 1), meaning of values squished 1 box, , not want :(
want put 1 column, in different rows (1,2,3,4,5,6).
i've searched web answer, seems answering if want values in 1 box opposite want.
perhaps 1 one, therefore insert ytable (title)values($title);, , puts of values in different rows in 1 column.

you going have split strings array, can 'loop' through them.

$title   = "aa, bb, cc, dd, ee, ff"; $pubdate = "aa, bb, cc, dd, ee, ff"; $link    = "aa, bb, cc, dd, ee, ff";  $titlearray   = explode(', ',$title); $pubdatearray = explode(', ',$pubdate); $linkarray    = explode(', ',$link);  //either: loop through array , build individual inserts for($i=0;$i<count($titlearray);$i++){      // generate insert each row     $sql = "insert ytable (title, pubdate, link)              values ('$titlearray[$i]', '$pubdatearray[$i]', '$linkarray[$i]')";  }  //or build single query string inside loop, , run @ end. 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -