ทำอย่างไรให้สามารถดึงข้อมูล $BARCODE ทั้งหมดจากฐานข้อมูลมาแส

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: ทำอย่างไรให้สามารถดึงข้อมูล $BARCODE ทั้งหมดจากฐานข้อมูลมาแส

โดย mindphp » 23/08/2007 12:15 am

ไม่เป็น ไร ครับ มีอะไร ก็ แลกเปลี่ยน ความรู้กันได้ครับ :-D :-D
ได้ผล ยังไง ทำยังไงไปบอกด้วยนะครับ

โดย ruti » 22/08/2007 10:26 pm

OK ครับขอบคุณมากครับ ต่อไปผมคงต้องทำให้ แสดงผลเป็นคอลัมภ์ผมจะพยายาม ดูก่อนแล้วจะมาถามท่านที่นี่อีกครั้งหนึ่งขอบคุณ ในความกรุณาและเมตตามาโดยตลอด*** ขอบคุณแทนนักเรียนนับร้อยรอคอย ผลงานของครูที่สำเร็จลงด้วยการช่วยเหลือของท่าน.

โดย ruti » 22/08/2007 10:00 pm

ขอบคุณครับได้หรือไม่จะรายงานให้ทราบอีกที

โดย mindphp » 22/08/2007 9:45 pm

แยก ส่วนที่ สร้าง รูปออกไป เป็น อีก ไฟล์ ครับ แล้ว
ใช้ tag img เพื่อ แสดง รูป แทน :) :) :)
ตัวอย่างเช่น
loop การแสดงผลแบบเดิม ที่ทำได้แล้ว
<img src="create_img.php?code=12345678" />
create_img.php คือ code ที่สร้างรูปที่เราแยกออกมา

โดย ruti » 22/08/2007 9:35 pm

ผมนำไปประยุกต์แล้วครับแต่ไม่สำเร็จจึงรบกวนท่านชี้แนะครับ
ท่านลองนำโค๊ด ของผมไปใช้ดูแล้วจะเห็นว่าแสดงผล ได้เพียงข้อมูลเดียวคือบรรทัดแรก หรือไม่ก็บรรทัดสุดท้ายผมพยายาม ประยุกต์มาหลายครั้งแล้วแต่ไม่สำเร็จเพราะผลที่ได้ผมต้องกา ให้เป็นบาร์โค๊ดครับแต่ถ้เป้น DATA ปกติทำได้ครับ รบกวนท่านช่วยแนะนำโค๊ดให้หน่อยครับ

โดย mindphp » 22/08/2007 9:22 pm

ได้ ข้อมูลเพียงข้อมูลเดียว ยังไง หรือครับ
ถ้าต้องการ แสดง ข้อมูลทั้งหมด ก็ ตามที่บอกน่ะครับ ต้อง ลอง เอา ไประยุกต์ต่อ :-D :-D

โดย ruti » 22/08/2007 7:53 pm

ถ้ามอีกครับอย่าเพิ่งปวดหัว
ผมได้ลองดูตามคำแนะนำแล้ว
สำหรับข้อมูลทั่วไปแสดงได้ไม่มีปัญหา
แต่ถ้าเอาตัวเลขจากฐานข้อมูลมาแทน size=18] $barcode="1234567";[/size] ในโคดข้างล่างนี้แล้วจะไม่สามารถแสดงในรูปแบบของบาร์โค๊ดได้ทั้งหมดจะได้เพียงแค่ ข้อมูลเดียวครับ

**************ขอบคุณครับ**********




<?php

$barcode="1234567";

if(isset($_GET["text"])) $text=$_GET["text"];
if(isset($_GET["format"])) $format=$_GET["format"];
if(isset($_GET["quality"])) $quality=$_GET["quality"];
if(isset($_GET["width"])) $width=$_GET["width"];
if(isset($_GET["height"])) $height=$_GET["height"];
if(isset($_GET["type"])) $type=$_GET["type"];
if(isset($_GET["barcode"])) $barcode=$_GET["barcode"];
if (!isset ($text)) $text = 1;
if (!isset ($type)) $type = 1;
if (empty ($quality)) $quality = 100;
if (empty ($width)) $width = 220;
if (empty ($height)) $height = 80;
if (!empty ($format)) $format = strtoupper ($format);
else $format="PNG";


switch ($type)
{
default:
$type = 1;
case 1:
Barcode39 ($barcode, $width, $height, $quality, $format, $text);
break;
}


//-----------------------------------------------------------------------------
// Generate a Code 3 of 9 barcode
//-----------------------------------------------------------------------------
function Barcode39 ($barcode, $width, $height, $quality, $format, $text)
{
switch ($format)
{
default:
$format = "JPEG";
case "JPEG":
header ("Content-type: image/jpeg");
break;
case "PNG":
header ("Content-type: image/png");
break;
case "GIF":
header ("Content-type: image/gif");
break;
}


$im = ImageCreate ($width, $height)
or die ("Cannot Initialize new GD image stream");
$White = ImageColorAllocate ($im, 255, 255, 255);
$Black = ImageColorAllocate ($im, 0, 0, 0);
//ImageColorTransparent ($im, $White);
ImageInterLace ($im, 1);



$NarrowRatio = 20;
$WideRatio = 55;
$QuietRatio = 35;


$nChars = (strlen($barcode)+2) * ((6 * $NarrowRatio) + (3 * $WideRatio) + ($QuietRatio));
$Pixels = $width / $nChars;
$NarrowBar = (int)(20 * $Pixels);
$WideBar = (int)(55 * $Pixels);
$QuietBar = (int)(35 * $Pixels);


$ActualWidth = (($NarrowBar * 6) + ($WideBar*3) + $QuietBar) * (strlen ($barcode)+2);

if (($NarrowBar == 0) || ($NarrowBar == $WideBar) || ($NarrowBar == $QuietBar) || ($WideBar == 0) || ($WideBar == $QuietBar) || ($QuietBar == 0))
{
ImageString ($im, 1, 0, 0, "Image is too small!", $Black);
OutputImage ($im, $format, $quality);
exit;
}

$CurrentBarX = (int)(($width - $ActualWidth) / 2);
$Color = $White;
$BarcodeFull = "*".strtoupper ($barcode)."*";
settype ($BarcodeFull, "string");

$FontNum = 3;
$FontHeight = ImageFontHeight ($FontNum);
$FontWidth = ImageFontWidth ($FontNum);
if ($text != 0)
{
$CenterLoc = (int)(($width-1) / 2) - (int)(($FontWidth * strlen($BarcodeFull)) / 2);
ImageString ($im, $FontNum, $CenterLoc, $height-$FontHeight, "$BarcodeFull", $Black);
}
else
{
$FontHeight=-2;
}


for ($i=0; $i<strlen($BarcodeFull); $i++)
{
$StripeCode = Code39 ($BarcodeFull[$i]);


for ($n=0; $n < 9; $n++)
{
if ($Color == $White) $Color = $Black;
else $Color = $White;


switch ($StripeCode[$n])
{
case '0':
ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$NarrowBar, $height-1-$FontHeight-2, $Color);
$CurrentBarX += $NarrowBar;
break;


case '1':
ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$WideBar, $height-1-$FontHeight-2, $Color);
$CurrentBarX += $WideBar;
break;
}
}


$Color = $White;
ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$QuietBar, $height-1-$FontHeight-2, $Color);
$CurrentBarX += $QuietBar;
}


OutputImage ($im, $format, $quality);
}


//-----------------------------------------------------------------------------
// Output an image to the browser
//-----------------------------------------------------------------------------
function OutputImage ($im, $format, $quality)
{
switch ($format)
{
case "JPEG":
ImageJPEG ($im, "", $quality);
break;
case "PNG":
ImagePNG ($im);
break;
case "GIF":
ImageGIF ($im);
break;
}
}


//-----------------------------------------------------------------------------
// Returns the Code 3 of 9 value for a given ASCII character
//-----------------------------------------------------------------------------
function Code39 ($Asc)
{
switch ($Asc)
{
case ' ':
return "011000100";
case '$':
return "010101000";
case '%':
return "000101010";
case '*':
return "010010100"; // * Start/Stop
case '+':
return "010001010";
case '|':
return "010000101";
case '.':
return "110000100";
case '/':
return "010100010";
case '-':
return "010000101";
case '0':
return "000110100";
case '1':
return "100100001";
case '2':
return "001100001";
case '3':
return "101100000";
case '4':
return "000110001";
case '5':
return "100110000";
case '6':
return "001110000";
case '7':
return "000100101";
case '8':
return "100100100";
case '9':
return "001100100";
case 'A':
return "100001001";
case 'B':
return "001001001";
case 'C':
return "101001000";
case 'D':
return "000011001";
case 'E':
return "100011000";
case 'F':
return "001011000";
case 'G':
return "000001101";
case 'H':
return "100001100";
case 'I':
return "001001100";
case 'J':
return "000011100";
case 'K':
return "100000011";
case 'L':
return "001000011";
case 'M':
return "101000010";
case 'N':
return "000010011";
case 'O':
return "100010010";
case 'P':
return "001010010";
case 'Q':
return "000000111";
case 'R':
return "100000110";
case 'S':
return "001000110";
case 'T':
return "000010110";
case 'U':
return "110000001";
case 'V':
return "011000001";
case 'W':
return "111000000";
case 'X':
return "010010001";
case 'Y':
return "110010000";
case 'Z':
return "011010000";
default:
return "011000100";
}
}


?>

โดย mindphp » 22/08/2007 6:52 pm

ถ้าจะแสดง ข้อมูล ทั้งหมด ลองใช้แบบนี้แทนครับ
while($row = mysql_fetch_array($db_query)) {
แสดงผล ข้อมูล
}

โดย ruti » 22/08/2007 5:36 pm

เอาใหม่นะครับท่าน
ปัญหาของผมตอนี้คือ
1.ไม่สามารถดึงข้อมูลจากฐานข้อมูลทั้งหมดมาแสดงตามลำดับได้
2.ต้องการแสดงผลเป็น8 คอลัมภ์(แต่อยากให้ผ่านข้อ1ก่อน)
3. ผมมีความรู้ทาง php น้อยนิด กำลังฝึกอยู่

**********ท่านลองนำโค๊ดของผมไปพรีวิวดูก่อนนะครับว่ามันโชว์มาแค่ข้อมูลเดียว**********ขอบคุณในความเมตตามาโดยตลอด

โดย mindphp » 22/08/2007 4:38 pm

ต้องเปลี่ยน วิธีการ fetch ข้อมูล ออกมา โชว์ดูครับ
นับข้อมูล แล้ว หาร แปด ปัดเศษขึ้น
แล้ว วนลูป fecth ข้อมูล :-D

ข้างบน