0
My question is the following, I have a field in a MYSQL table that stores data and this data is displayed to the user.
This data is entered by users, however, users can also add information in this table field and this information is concatenated with the old ones (i.e., the value is not replaced).
Only when it is displayed it is kind of bizarre everything in one row. See the table and the view in html.
Output on Page
Just to be clear, I first inserted Flamengo, then Vasco, then Botafogo, then Palmeiras and finally Santos.
Only I would like every time I add data in this field, the items are displayed on the HTML page breaking line. That is, Each club stayed in one line.
I’ve been able to make room for information, but the break in line is breaking me.
If you can help me, I’d be grateful.
I used AJAX to send the data and PHP to query the Mysql database.
I don’t think we need to add the code to that question.
I hope I’ve been as clear as possible. Thank you!
I entered the Code to better detail the situation.
<div class="modal" tabindex="-1" id="modal-observacoes">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header bg-success">
<button class="close" aria-label="close" data-dismiss="modal">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Inserir Observações na Atividade</h4>
</div>
<div class="modal-body bg-success">
<form id="inserir-observacoes">
<div class="form-group col-lg-12" style="font-size: 120%">
<label for="observacoes-modal">Observações - Máximo de 500 caracteres</label>
<textarea class="form-control" name="observacoes-modal" id="observacoes-modal" style="resize: none" rows="4" maxlength="500" required></textarea>
</div>
<input type="text" name="codigo-modal-observacoes" id="codigo-modal-observacoes">
<input type="submit" class="btn btn-primary" name="enviar-modal-observacoes" id="enviar-modal-observacoes" value="Inserir">
</form>
<!--
<div id="confirmacao-inserir-informacoes">
<h4></h4>
</div>
-->
</div>
</div>
</div>
</div>
<!-- PARTE PHP QUE FAZ REALIZA O RECEBIMENTO DOS DADOS E EXECUTA A QUERY -->
<?PHP
if($_POST)
{
//PREENCHE AS VARIÁVEIS COM OS DADOS VINDOS DOS CAMPOS DO FORMULÁRIO
$observacoes = !empty($_POST["observacoes-modal"]) ? " \n" . $_POST["observacoes-modal"] : null;
$codigo = !empty($_POST["codigo-modal-observacoes"]) ? $_POST["codigo-modal-observacoes"] : null;
$pesquisar_observacoes = "UPDATE tbl_atividades SET DETALHES = CONCAT(DETALHES, '$observacoes'), DATA_DETALHES = NOW(), DETALHE_VISUALIZADO = '$resultado' WHERE codigo = $codigo";
$operacao_insercao_observacoes = mysqli_query($conecta, $pesquisar_observacoes) or die("Erro no Update");
}
?>
I WAS ABLE TO FIX IT WITH SAM’S ANSWER. I ADDED A
CONCATENATED WITH THE TEXT COMING FROM THE FORM IN THE PHP VARIABLE ENTERING THE UPDATE QUERY.
But now I’m faced with another problem. When the column has the value 'null' in the database, I cannot concatenate with the value coming from the form.
An idea would be to add after each team name a "
_
", guy:Flamengo_Vasco_Botafogo_Atlético Mineiro_
, and in PHP replace "_
" by a<br>
.– Sam
I think adding the code is necessary. Where are you getting input from? Is it from a textarea? from a WYSIWYG? The strings contain something like
\n
while in Javascript?– Andre
In place of space you substitute for
<br>
, example:echo str_replace(' ', '<br>', $valor_banco);
.– novic
You used a
textarea
to enter this information? Because if so, when the user presses theenter
generates the\n
automatically. Then, in php, you can usenl2br
or thestr_replace
and insert the<br>
in the text. When you make the selection will already be there!– Andrei Coelho
@Lipespry I just don’t know if it’s really that! = ) But if you have an answer in mind about that, you can do!
– Andrei Coelho
@Lipespry who said that his comment responds, that is defined by the author of the question!
– novic
@Lipespry yes, but, that is the author of the question decides, he could get into the comment and say that is the answer, but, your assumption may be wrong and then you know that life here is not easy, I’m just warning and sorry for that.
– novic
The problem, in my view, is that there are many solutions to this answer. To get to something closer would be nice to know how the data is added. In this case, Flamento and Vasco are together!
– Andrei Coelho
And actually @Andreicoelho is a bad option as it adds.
– novic
@Andreicoelho Do replace by space will not work because if the team has more than one word (ex. Atlético Mineiro) will insert a
<br>
in the middle of the team name:Atlético<br>Mineiro
– Sam
truth @Sam ... Why I think to get into something closer would be better to see how the die is entered! That’s where I mean! And looking at what you have said now, I believe that no regex or replace will result in a solution in the way the data is. It is necessary to change the way it is inserted... In my view...
– Andrei Coelho
He could already bench the
<br>
, guy:Flamengo<br>Vasco<br>Botafogo etc.
, but I suggested putting a_
in place of<br>
because it saves space in the bank:Flamengo_Vasco_Botafogo etc.
... then just do the replace:str_replace('_', '<br>', $valor_banco);
– Sam
@Sam exact! That was the solution I referred to in the first comment! He already put in the bank the <br> of life!
– Andrei Coelho
@Lipespry I know the purpose of the site, but that being an assumption is not an answer, that’s what I’m saying. Comment is not answer even below has happened other questions that I agree, if the question guy says nothing is complicated to know what he needs. In fact the information could not be recorded like this.
– novic