INSERT CONCATENATE PHP MYSQL

0

I want to insert a record in mysql, according to the id already has something predefined

example

I will insert a post with the category with id = 2, so the name of my post will be something that I have already defined the rest of the past for the form, type for the posts with category of id = 2 the name of these posts will have "REDIO" + value passed by the form, half confused how to do something like this?

    
asked by anonymous 18.07.2016 / 05:57

2 answers

2
if($categoria->id==2)
   $post->titulo='REDIO'.$_POST['form']['titulo'];

UPDATE:

//O seu post deve conter o id da categoria, logo
$idCategoria = $_POST['form']['id_categoria'];
//recupera do banco de dados o OBJETO categoria
$categoria = getCategoriaBancoDeDados($idCategoria);
//O objeto categoria tem o atributo prefixo
$post->titulo=$categoria->prefixo.$_POST['form']['titulo'];

Database

<table style="border:1px solid #ccc">
  <tr style="border:1px solid #ccc">
    <th>categorias</th>
  </tr>
  <tr>
    <td style="border:1px solid #ccc">id</td>
  </tr>
  <tr>
    <td style="border:1px solid #ccc">prefixo</td>
  </tr>
  <tr>
    <td style="border:1px solid #ccc">[outros campos]</td>
  </tr>
    
18.07.2016 / 07:00
1

I do not quite understand, do you want that depending on id , the title of the post has a pre-determined prefix?

For example:

Título original = "Alguma coisa"
ID = 1
Prefixo = "TESTE"

Titulo final = "TESTEAlguma coisa"

Would that be?

If it is, it would be interesting to create a table of prefixes, containing the ID and prefix you want to use, then make a SELECT to return the prefix of the requested ID, only to% / p>     

18.07.2016 / 07:08