douzepao0281 2016-06-13 21:05
浏览 21

条形码不能读取mysql中的行

Good evening to all, I would like to print a bar code for each type of pasta. I adapted this code to mine, but it does not read the data that is within the code field. (Which is created by the php rand () code) I would choose the id through the bar code to be printed.

<html>
<head>
<?php
$con=mysqli_connect("localhost","xxx","xxx","xxx");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id = $_GET['id'];
$query= "select * from pasta where id='$id'";
$result = mysqli_query($con,$query);
while ($row = mysqli_fetch_assoc($result)){
$rand=$row['codice'];
}
?>
<br>
<div style="width:25px: height:500px; border:2px, solid #000; align="center"">
<div align="center">
<img src="http://bcgen.com/demo/linear-dbgs.aspx?=D<?php echo $rand  ?>">
<br>
<form action ="stampa.php" method="post">
<input  type="button" value="stampa"
onClick="window.print()"/>
</form>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • dongluo8303 2016-06-13 22:50
    关注

    It seems to me you have a loop that reads all rows matching the select, and in a loop overwrite all values of 'codice' but the last, and then create some html that will (eventually, in the browser) generate your barcode.

    Solarflare is quite correct: check that your input is what you think it is, and that the query result has the fields you expect, too. It is considered good practice to always mention field names explicitly -- that is, don't use * -- so that mismatched names are easier to spot.

    If you are only expecting one value from the DB then you don't need a while loop, and perhaps a LIMIT 1 in the SQL would be good too. If not, then you need to nest the html within the php loop, so you get more than one img tag output.

    ... and definitely fix the html. It would help if you indented the code as this immediately shows where things don't match up.

    [Talking of which, better practice would be to generate the barcode server-side, not make the browser/client do it from a 3rd party site.]

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算