send hashtags in different columns in mysql database

Asked

Viewed 42 times

1

I would like to insert each word "hashtag" in a table column, I am using this example:

    <form name="formulario" method="post" enctype="multipart/form-data" action="">

    <input name="hashtag`" type="text"/>

    <input type="submit" value="enviar"/>

    </form>

    <?php
    if(isset($_POST)){

    $hashtag = $_POST['hashtag'];

        $ext = implode(",",$hashtag`);
        var_dump($ext);

        /*resultado da impressão:
        string '#tag1,#tag2' (length=20)
        */

                $insert = DB::getConn()->prepare('INSERT INTO `table` SET `hashtag`=?');
                return $insert->execute(array($ext)) ? 1 : 0;

    }

In mysql database resulted

         id|1|hashtag|#tag1,#tag2

I would like each word to be inserted in a column:

         id|1|hashtag|#tag1
         id|2|hashtag|#tag2         
  • 1

    Want to insert in a different column or a new row? You have different columns for each hash?

  • @Sergio , yes I would like each word to be inserted separately in each column of the table ex: #tag1 in the first, #tag2 in the second

  • Do these columns have names? In this case you have to have a finite/static number of columns and tags, that is, a tag for each column. Or you want to insert a tag per line?

  • Do not use implode. foreach $hashtag and Insert for each. If the table supports, you can use transactions to ensure integrity. If you use native functions, just one prepare to save data on database communication (PDO by default only simulates the Prepared statements, losing this advantage, but mysqli makes native)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.