0
I’m having trouble using Jsbarcode and PHP. I dynamically feed the codes through a list. But when using the code within the bar code loop which is the following:
<img id="barcode"/>
<script>
var codigo = '<?php echo $codigo_barra['codigo_barras'];?>';
JsBarcode("#barcode", codigo , {
displayValue:true,
fontSize:24,
lineColor: "#0cc"
});
</script>
it repeatedly generates only 1 code and I have 4 different codes generated in the variable $codigo_barra['codigo_barras']
. What am I doing wrong in this case?
Below the full code of the page.
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="css/etiquetas.css">
<script src='js/JsBarcode.all.min.js'></script>
</head>
<body>
<?php foreach($codigo_barras as $codigo_barra):
?>
<div class="card" style="width: 18rem;">
<div class="card-body">
<table>
<tr>
<td>
<div><h2><?=$codigo_barra['desc_produto'];?></h2></div>
<input type="hidden" name="codigo_barras" value="<?=$codigo_barra['codigo_barras'];?>">
</td>
</tr>
<tr>
<td>
<table class="table table-bordered">
<tr>
<?php
$produtos_grade = buscaCompraProdutoGrade($conexao, $id_compra, $codigo_barra['id_sequencia']);
foreach ($produtos_grade as $produto_grade):
?>
<td>
<div class="form-group">
<div><kbd><label for="inputCity">
<?=$produto_grade['tamanho'];?></label>
</kbd><br>
<b><label for="inputCity"><?=$produto_grade['quantidade'];?></label></b>
</div>
</div>
</td>
<?php endforeach ?>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<div>Data previsão: <b><?php
$data = date_create($codigo_barra['previsao']);
echo date_format($data,'d/m/Y');?>
</b></div>
</td>
</tr>
<tr>
<td>
<div>
<img id="barcode"/>
<script>
var codigo = '<?php echo $codigo_barra['codigo_barras'];?>';
JsBarcode("#barcode", codigo , {
displayValue:true,
fontSize:24,
lineColor: "#0cc"
});
</script>
<?php echo $codigo_barra['codigo_barras'];?>
</div>
</td>
</tr>
</table>
</div>
</div>
<?php endforeach; ?>
</body>
Not knowing how you generated the value of
$codigo_barra['codigo_barras']
, how was the value generated and how should be impossible to answer.– Woss
I edited the question with full code
– Bruno Leonardo
id
should be unique, you’re repeating theid
barcode
. And the functionJSBarcode
is pointed fixed to a singleid
– Gabriel Heming
so if I put the barcode as its own id and game in the Jsbarcode function it gives the error: Jsbarcode.all.min.js:2 Uncaught Domexception: Failed to execute 'querySelectorAll' on 'Document': '#000120000001000063002001' is not a Valid selector. That is, the library itself makes a querySelectorAll
– Bruno Leonardo
The ID used is invalid for CSS, see this thread: https://github.com/DevExpress/testcafe/issues/1899#issuecomment-338203498 or in this link: https://www.w3.org/TR/CSS21/syndata.html#value-def-Identifier
– Gabriel Heming