Insert multiple rows into mysql (items separated by comma)

前端 未结 7 576
执笔经年
执笔经年 2021-01-14 12:57

I have a small problem :) I was searching the web but didn\'t find any solutions.

I have a value like this (got it from $_GET[])

tag1, tag2, tag3, tag4

相关标签:
7条回答
  • 2021-01-14 13:33

    Hi greetings from UK :)
    Can't you just loop through the querystring fields and add one row to the database at a time?

    e.g.

    <?php
    
    $id = 33;
    $value_list = 'tag1,tag2,tag3,tag4';
    $values = explode(',', $value_list);
    foreach ($values as $value)
    {
        $sql = "INSERT INTO table (id, value) VALUES ($id, '$value');";
        //.. execute SQL now
        echo '<p>' . $sql . '</p>';
    }
    
    ?>
    

    I uploaded this to http://cyba.co/test.php so you can see the output.

    0 讨论(0)
提交回复
热议问题