เพิ่มเติม : ข้อมูลจาก MySQL Database qrcodeoptiontag ตรง shortname มาใส่แทนที่ช่องกรอก Data ในระบบ phpqrcode ใส่ในรูปแบบ Datalist Tag ตามตัวอย่างใน Link : https://www.w3schools.com/tags/tag_datalist.asp ครับ
1. qrcodeoptiontag.sql ที่จะนำข้อมูลจาก MySQL Database qrcodeoptiontag ตรง shortname มาใส่แทนที่ช่องกรอก Data ในระบบ phpqrcode ครับ
-- phpMyAdmin SQL Dump
-- version 4.8.4
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Apr 02, 2021 at 09:05 AM
-- Server version: 10.1.37-MariaDB
-- PHP Version: 7.3.1
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `qrcodeoptiontag`
--
-- --------------------------------------------------------
--
-- Table structure for table `qrcodeoptiontag`
--
CREATE TABLE `qrcodeoptiontag` (
`shortname` varchar(13) CHARACTER SET utf8 DEFAULT NULL,
`longname` varchar(40) CHARACTER SET utf8 DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `qrcodeoptiontag`
--
INSERT INTO `qrcodeoptiontag` (`shortname`, `longname`) VALUES
('123', 'Test1'),
('456', 'Test2'),
('789', 'Test3'),
('0123', 'Test4'),
('4567', 'Test5');
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
ตัวอย่าง Code เพิ่มเติม ครับ
2. index.php
<?php
/*
* PHP QR Code encoder
*
* Exemplatory usage
*
* PHP QR Code is distributed under LGPL 3
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
error_reporting(error_reporting() & ~E_NOTICE);
//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.'test.png';
//processing form input
//remember to sanitize user input in real-life solution !!!
$errorCorrectionLevel = 'L';
if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
$errorCorrectionLevel = $_REQUEST['level'];
$matrixPointSize = 4;
if (isset($_REQUEST['size']))
$matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10);
if (isset($_REQUEST['data'])) {
//it's very important!
if (trim($_REQUEST['data']) == '')
die('data cannot be empty! <a href="?">back</a>');
// user data
$filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
QRcode::png($_REQUEST['data'], $filename, $errorCorrectionLevel, $matrixPointSize, 2);
}
//display generated file
echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" /><br>';
//display generated file
echo '<h1 style="margin-left: 17.5px;">'.$_REQUEST['data'].'</h1><br>';
//config form
echo '<form action="index.php" method="post">
Data: <input name="data" value="'.(isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):'Test').'" /><br><br>
ECC: <select name="level">
<option value="H"'.(($errorCorrectionLevel=='H')?' selected':'').'>H - best</option>
</select><br><br>
Size: <select name="size">';
for($i=8;$i<=8;$i++)
echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>';
echo '</select><br><br>
<input type="submit" value="สร้าง QR Code"></form>';
แจ้งข่าวเพิ่มเติม : สามารถแก้ปัญหาเรื่อง ต้องเขียน Code อย่างไร จึงจะนำข้อมูลจาก MySQL Database qrcodeoptiontag ตรง shortname มาใส่แทนที่ช่องกรอก Data ในระบบ phpqrcode ได้แล้วครับ
Code ทั้งหมด ที่ใช้งานได้ 100% มีดังนี้ครับ
1. qrcodeoptiontag.sql ที่จะนำข้อมูลจาก MySQL Database qrcodeoptiontag ตรง shortname มาใส่แทนที่ช่องกรอก Data ในระบบ phpqrcode ครับ
-- phpMyAdmin SQL Dump
-- version 4.8.4
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Apr 02, 2021 at 09:05 AM
-- Server version: 10.1.37-MariaDB
-- PHP Version: 7.3.1
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `qrcodeoptiontag`
--
-- --------------------------------------------------------
--
-- Table structure for table `qrcodeoptiontag`
--
CREATE TABLE `qrcodeoptiontag` (
`shortname` varchar(13) CHARACTER SET utf8 DEFAULT NULL,
`longname` varchar(40) CHARACTER SET utf8 DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `qrcodeoptiontag`
--
INSERT INTO `qrcodeoptiontag` (`shortname`, `longname`) VALUES
('123', 'Test1'),
('456', 'Test2'),
('789', 'Test3'),
('0123', 'Test4'),
('4567', 'Test5');
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
2. index.php
<?php
header('Content-Type: text/html; charset=UTF-8');
include ("connect.php");
$db = new mysqli('localhost', $dbuser, $dbpass, $dbname);
mysqli_set_charset($db, "utf8");
if (!$db) {
exit('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error()); }
?>
<?php
/*
* PHP QR Code encoder
*
* Exemplatory usage
*
* PHP QR Code is distributed under LGPL 3
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
error_reporting(error_reporting() & ~E_NOTICE);
//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.'test.png';
//processing form input
//remember to sanitize user input in real-life solution !!!
$errorCorrectionLevel = 'L';
if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
$errorCorrectionLevel = $_REQUEST['level'];
$matrixPointSize = 4;
if (isset($_REQUEST['size']))
$matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10);
if (isset($_REQUEST['data'])) {
//it's very important!
if (trim($_REQUEST['data']) == '')
die('ข้อมูลที่ช่องใส่รหัส ไม่สามารถปล่อยให้ว่างได้ <br><br><a href="?">ย้อนกลับ</a>');
// user data
$filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
QRcode::png($_REQUEST['data'], $filename, $errorCorrectionLevel, $matrixPointSize, 2);
}
//display generated file
echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" /><br>';
//display generated file
echo '<h1 style="margin-left: 17.5px;">'.$_REQUEST['data'].'</h1><br>';
//config form
echo '<form action="index.php" method="post">
ใส่รหัสที่ช่องนี้: <input id="material01" name="data" list="material" autocomplete="off"><datalist id="material">';
$queryusers1 = "SELECT * FROM `qrcodeoptiontag` ";
$db01 = mysqli_query($db, $queryusers1);
while ( $d1=mysqli_fetch_assoc($db01)) {
echo "<option value='".$d1['shortname']."' />".$d1['longname']."</option>";
}
echo '</datalist><br><br> ECC: <select name="level">
<option value="H"'.(($errorCorrectionLevel=='H')?' selected':'').'>H - best</option>
</select><br><br>
Size: <select name="size">';
for($i=8;$i<=8;$i++)
echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>';
echo '</select><br><br>
<input type="submit" value="สร้าง QR Code"></form>';