Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有SQL语句的PHP二维码生成器_Php_Mysql_Qr Code - Fatal编程技术网

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

带有SQL语句的PHP二维码生成器,php,mysql,qr-code,Php,Mysql,Qr Code,我想使用MYSQL查询的结果,并通过PhpQrCode生成一批QR码,其中包含以下php脚本。我需要的只是显示HTML页面上生成的条形码列表。这是我到目前为止写的: <?php include "qrlib.php"; require "conf/config.php"; $con = mysql_connect(DBSERVER,DBUSER,DBPASS); mysql_select_db(DBNAME, $con);

我想使用MYSQL查询的结果,并通过PhpQrCode生成一批QR码,其中包含以下php脚本。我需要的只是显示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属性中的链接。

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

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

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

echo '<img src="', $src, '">';
$qr_code=base64_编码(QRcode::png($row['Description']);
$src='数据:图像/png;base64'.$qr_码;
回声';
解决方法如下:

<?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存储为文件。

将您的任务拆分为子任务,并逐个解决它们。然后,当你在解决更具体的问题时,试着再问一次。例如,第一个任务可能是了解
img src
接受什么。我敢打赌,QRcode::png()不会返回包含以下代码的链接,我只显示了一个二维码。
code
code
一个或多个图像,但都是相同的二维码?它只显示一个二维码,所以只有一个输出?您确定查询返回多行吗?如果我的解决方案奏效,一次感谢和投票会很好。我没有登录调试您的整个脚本。感谢您的帮助-是的,查询返回多行,因为我通过一个简单的echo语句进行了尝试,它显示了正确的结果。