PHP 带有 SQL 语句的二维码生成器

PHP QR Code Generator with SQL statement

我想使用 MYSQL 查询的结果并通过 PhpQrCode 生成一批具有以下 php 脚本的 QR 码。我需要的只是显示在 HTML 页面上生成的条形码列表。这是我到目前为止写的:

<?php

include "qrlib.php";
require "conf/config.php";

            $con = mysql_connect(DBSERVER,DBUSER,DBPASS);
            mysql_select_db(DBNAME, $con); 
            $barcodes = mysql_query( "SELECT Description FROM dbo_sensorsandparts ORDER BY ID ASC");



while ($row = mysql_fetch_array($barcodes))
{

echo "<html>";

echo "<img src="; 

QRcode::png ($row['Description']);
echo ">";
}
?> 

查询是正确的,因为我对其进行了测试,但我只得到一个带有某种损坏图像的空白页面。有人可以帮我看看我做错了什么吗?

谢谢

解决如下:

<?php    
require "conf/config.php";

            $con = mysql_connect(DBSERVER,DBUSER,DBPASS);
            mysql_select_db(DBNAME, $con); 
            $barcodes = mysql_query( "SELECT Description FROM dbo_sensorsandparts ORDER BY ID ASC");



    //set it to writable location, a place for temp generated PNG files
    $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;

    //html PNG location prefix
    $PNG_WEB_DIR = 'temp/';

    include "qrlib.php";    

    //ofcourse we need rights to create temp dir
    if (!file_exists($PNG_TEMP_DIR))
        mkdir($PNG_TEMP_DIR);


   $filename = $PNG_TEMP_DIR.'label.png';


    while ($row = mysql_fetch_array($barcodes))


{
  $filename = $PNG_TEMP_DIR.'label'.$row['Description'].'.png';

        QRcode::png($row['Description'], $filename); 

        echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" /><hr/>'; 
echo $filename;   

    }    

 ?> 

要在html页面中渲染图像,将返回的QRcode图像保存在一个位置,然后在src属性中将其指定为link <img> 个标签。

如果QRcode::png returns原始图像数据,使用数据URI显示:

$qr_code = base64_encode(QRcode::png ($row['Description']));

$src = 'data: image/png;base64,'.$qr_code;

echo '<img src="', $src, '">';

解决如下:

<?php    
    require "conf/config.php";

                $con = mysql_connect(DBSERVER,DBUSER,DBPASS);
                mysql_select_db(DBNAME, $con); 
                $barcodes = mysql_query( "SELECT Description FROM dbo_sensorsandparts ORDER BY ID ASC");



        //set it to writable location, a place for temp generated PNG files
        $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;

        //html PNG location prefix
        $PNG_WEB_DIR = 'temp/';

        include "qrlib.php";    

        //ofcourse we need rights to create temp dir
        if (!file_exists($PNG_TEMP_DIR))
            mkdir($PNG_TEMP_DIR);


       $filename = $PNG_TEMP_DIR.'label.png';


        while ($row = mysql_fetch_array($barcodes))


    {
      $filename = $PNG_TEMP_DIR.'label'.$row['Description'].'.png';

            QRcode::png($row['Description'], $filename); 

            echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" /><hr/>'; 
    echo $filename;   

        }    

     ?> 

我已通过变量 $filename 将 PNG 存储为文件。