INSERT CONCATENATE PHP MYSQL

Asked

Viewed 240 times

0

I am wanting that when entering a register in mysql , according to the id already have something predefined

example

I will insert a post with the category id = 2 , then the name of my post will be something I have already defined more the rest passed by the form , type for posts with category id = 2 the name of these posts will have "REDIO" + value passed by the form , kind of messed up has something to do ?

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>

  • Friend good idea but n is right for my problem , because I want you to identify the id of the category and so search the prefix , because it will be several

  • check now .

1

I don’t quite understand, you want it depending on the id, the post title has a predetermined 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 prefix table, containing the ID and prefix you want to use, then make a SELECTto return the prefix of the requested ID, only to do the INSERT.

  • Hello friend is this msm , however I can not understand how I would do it could give a practical example or describe this procedure better ?

Browser other questions tagged

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