william
william

Reputation: 606

Split a comma separated string into multiple columns into db - php

I need some help to insert comma separates strings into multiple columns into db.

My $_POST['search'] value output. [search] => schools,books,mobile

How do i make an foreach or for to insert those data into db? :S

Upvotes: 0

Views: 2799

Answers (2)

william
william

Reputation: 606

                    $post = $_POST['search'];
                $queries = explode( ',', $post );
                foreach( $queries as $query ) {
                    $db->Execute("INSERT INTO tags SET name = '".$query."'");
                }

This seems to worked for me..

I was using @klez's informations

Upvotes: 0

Federico klez Culloca
Federico klez Culloca

Reputation: 27119

You can use the explode function.

$queries=explode(',', $_POST['search']

Now $query is an array containing the separated values. Then you do your query, but without further informations about that, I have to stop here.

Upvotes: 1

Related Questions