6
I have a table with a field type text
, the field stores a string imported via archive .csv
, the same was inserted without line break and I’m trying to insert it, I was able to identify that the line break should happen after the " - ", hyphen space hyphen, I tried this code snippet:
<?php
include('Connections/conexao.php');
mysql_select_db($database_conexao, $conexao);
$query_rsPesquisa = "SELECT * FROM `produtos` WHERE status = 1";
$rsPesquisa = mysql_query($query_rsPesquisa, $conexao) or die(mysql_error());
$row_rsPesquisa = mysql_fetch_assoc($rsPesquisa);
$totalRows_rsPesquisa = mysql_num_rows($rsPesquisa);
do {
$id_produto = 10;
$string = $row_rsPesquisa['detalhes'];
if( strstr($string," - ")){
$novaString = wordwrap($string, 20, "<br />\n");
$UpDetalhe ="UPDATE produtos SET detalhes = $novaString WHERE id_produto = $id_produto;";
$sucesso = mysql_query($UpDetalhe) or die(mysql_error("Erro ao alterar registro"));
if ($sucesso > 0) {
echo "Próximo registro";
}
}
} while ($row_rsPesquisa = mysql_fetch_assoc($rsPesquisa));
?>
The plain text is like this:
"Measures of the products of photo(s) (s) (cm): - 3 Places + Chaise: - Width: 281 - Depth: 161 - Height: 94 - 3 Places: - Width: 225 - Depth: 94 - Height: 94 - 2 Places: - Width: 170 - Depth: 94 - Height: 94 - Modulated 2 Places + Corner + 3 Places: - Width (2 Places + Corner): 246 - Width (3 Places + Corner): 301 - Depth: 94 - Height: 94 - Size options: - 1 Place - 2 Places - 3 Places - Modulated (seat, chaise and corner). - Model also has puff option. - Coating: - Various options in fabric and synthetic leather."
After my attempt it was like this:
Medidas dos<br />
produtos da(s)<br />
foto(s) (cm):2<br />
Lugares: - <br />
Largura: 212 - <br />
Profundidade: 90 - <br />
Altura: 86 - 3<br />
Lugares + Chaise: - <br />
Largura: 212 - <br />
Profundidade: 155 - <br />
Altura: 86 -<br />
Opções de tamanho:<br />
- 2 Lugares - 3<br />
Lugares - Modulado<br />
(assento, chaise e<br />
canto). -<br />
Revestimento: - <br />
Várias opções em<br />
couro natural e<br />
I’d like to keep it that way:
Medidas dos produtos da(s) da(s) foto(s) (cm):
2 Lugares:
- Largura: 212
- Profundidade: 90
- Altura: 86
3 Lugares + Chaise:
- Largura: 212
- Profundidade: 155
- Altura: 86
- Opções de tamanho:
- 2 Lugares
- 3 Lugares
- Modulado (assento, chaise ecanto).
- Revestimento:
- Várias opções em couro natural e couro sintético.
In displaying the variable on my page I am using it without success:
echo nl2br($row_rsProdutos['detalhes']);
<textarea name="test" required>PUT YOUR TEXT HERE. THE DATABASE WILL IDENTIFY THE BREAKS</textarea>
– Lollipop
Hello @Lollipop, I did the recommended but the text is still without the desired formatting, thanks for the tip.
– adventistapr
Are you sure you want to save the data in this format to a single table field in the database? There is a pattern in the data. CSV, which you could think of in a simple modeling and get a better and organized control. Recording this way, without a minimum modeling, will have a redoubled work in the future..
– Daniel Omine
Hello @Daniel Omine, I received this spreadsheet converted into . csv from client.
– adventistapr
@adventistapr.... you understood what I posted?
– Daniel Omine
Hello @Daniel Omine, got it, thanks for the tip.
– adventistapr