สอบถามว่า ต้องเขียน Code อย่างไร จึงจะนำข้อมูลจาก MySQL Database qrcodeoptiontag มาใส่แทนที่ช่องกรอก Data ในระบ

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สอบถามว่า ต้องเขียน Code อย่างไร จึงจะนำข้อมูลจาก MySQL Database qrcodeoptiontag มาใส่แทนที่ช่องกรอก Data ในระบ

สอบถามว่า ต้องเขียน Code อย่างไร จึงจะนำข้อมูลจาก MySQL Database qrcodeoptiontag มาใส่แทนที่ช่องกรอก Data ในระบ
สอบถามว่า ต้องเขียน Code อย่างไร จึงจะนำข้อมูลจาก MySQL Database qrcodeoptiontag ตรง shortname มาใส่แทนที่ช่องกรอก Data ในระบบ phpqrcode ได้ครับ
 
ซึ่งผมได้ศึกษา Code ระบบ phpqrcode จากเว็บ https://github.com/t0k4rt/phpqrcode ครับ
 
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:&nbsp;<input name="data" value="'.(isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):'Test').'" /><br><br>
        ECC:&nbsp;<select name="level">
            <option value="H"'.(($errorCorrectionLevel=='H')?' selected':'').'>H - best</option>
        </select><br><br>
        Size:&nbsp;<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>';

3. ไฟล์ระบบ phpqrcode ทั้งหมด ครับ
 


Sumate Mephokkij 202.151.7.xxx 02-04-2021 14:42:46

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
เพิ่มเติม : ข้อมูลจาก MySQL Database qrcodeoptiontag ตรง shortname มาใส่แทนที่ช่องกรอก Data ในระบบ phpqrcode ใส่ในรูปแบบ  Datalist Tag ตามตัวอย่างใน Link : https://www.w3schools.com/tags/tag_datalist.asp ครับ

พร้อมกับปรับปรุงเนื้อหาในกระทู้ ไม่ให้มี Code CSS ติดในตัวอย่าง Code ดังนี้ครับ


สอบถามว่า ต้องเขียน Code อย่างไร จึงจะนำข้อมูลจาก MySQL Database qrcodeoptiontag ตรง shortname มาใส่แทนที่ช่องกรอก Data ในระบบ phpqrcode ได้ครับ
 
ซึ่งผมได้ศึกษา Code ระบบ phpqrcode จากเว็บ https://github.com/t0k4rt/phpqrcode ครับ
 
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:&nbsp;<input name="data" value="'.(isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):'Test').'" /><br><br>
        ECC:&nbsp;<select name="level">
            <option value="H"'.(($errorCorrectionLevel=='H')?' selected':'').'>H - best</option>
        </select><br><br>
        Size:&nbsp;<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>';

3. ไฟล์ระบบ phpqrcode ทั้งหมด ครับ
 


Sumate Mephokkij 202.151.7.xxx 02-04-2021 15:01
 ความคิดเห็นที่ 2
เพิ่มเติม2 : ตัวอย่าง Code Datalist Tag ที่ใช้ในการดึงข้อมูลจาก MySQL Database qrcodeoptiontag ตรง shortname มาใส่แทนที่ช่องกรอก Data ในระบบ phpqrcode ครับ

4. connect.php

<?php
    $dbname = 'qrcodeoptiontag';
    $dbuser = 'root';
    $dbpass = '';
?>

5. datalistdisplay.php

<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1">
<style>
input, label {
  font-size: 36px;
}
</style>
</head>

<body>

    <?php    
	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());    }

	?>

<label for="material"><b>Sample Datalist Display</b></label><br><br>

	  <input id="material01" name="material" list="material">	  

	  <datalist id="material">          

	  <?php          $queryusers1 = "SELECT * FROM `qrcodeoptiontag` ";    

	  $db01 = mysqli_query($db, $queryusers1);    	

	  while ( $d1=mysqli_fetch_assoc($db01)) {        
	  echo "<option value='".$d1['shortname']."'></option>";    

	  }    ?>      

	  </datalist>	        

</body>
</html>


Sumate Mephokkij 1.47.5.xxx 02-04-2021 16:49
 ความคิดเห็นที่ 3
แจ้งข่าวเพิ่มเติม : สามารถแก้ปัญหาเรื่อง ต้องเขียน 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">
        ใส่รหัสที่ช่องนี้:&nbsp;<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:&nbsp;<select name="level">
            <option value="H"'.(($errorCorrectionLevel=='H')?' selected':'').'>H - best</option>
        </select><br><br>
        Size:&nbsp;<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>';

3. connect.php

<?php
    $dbname = 'qrcodeoptiontag';
    $dbuser = 'root';
    $dbpass = '';
?>

4. datalistdisplaytest.php (เป็น Code ทดสอบระบบ Datalist ใน PHP ซึ่งทดสอบแล้ว ใช้งานได้ครับ)

<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1">
<style>
input, label {
  font-size: 36px;
}
</style>
</head>

<body>

<?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());    }
 
?>

<label for="material"><b>Sample Datalist Display</b></label><br><br>

	  <input id="material01" name="data" list="material" autocomplete="off">	  

	  <datalist id="material">          

	  <?php          $queryusers1 = "SELECT * FROM `qrcodeoptiontag` ";    

	  $db01 = mysqli_query($db, $queryusers1);    	

	  while ( $d1=mysqli_fetch_assoc($db01)) {        
	  echo "<option value='".$d1['shortname']."' />".$d1['longname']."</option>"; 

	  }    ?>      

	  </datalist>	        

</body>
</html>

5. ไฟล์ระบบ phpqrcode ทั้งหมด ที่ใช้งานได้ 100% ครับ

https://drive.google.com/file/d/1_sIStH_Gq8LUQI9UBKdaZD2sr8HnFyQd/view?usp=sharing

 


Sumate Mephokkij 110.77.192.xxx 19-09-2021 16:02
1






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ