>> PHP ช่วยด้วยครับ +1 <<

เริ่มโดย bankker6480, 07 กุมภาพันธ์ 2013, 03:07:33

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

bankker6480

ไอตัวแดงๆคือผมจะเอา ข้อมูลจาก db เข้าไปเก็บค่าในนั้น ไม่ทราบว่าถูกไหมครับมี "" ครอบ :wanwan011:

if($product_id == "<?=$objResult["FilesID"];?>")
{
      $product_name = "<?=$objResult["Name"];?>";
      $product_class = "air";
      $product_version = "air-123";
      $unit = "20";
      $priceperunit = "45000";

      $product_title = $product_name." ".$product_class." รุ่น ".$product_version; // นำชื่อสินค้า , ชื่อรุ่น , รหัสสินค้า มาต่อเข้าด้วยกัน
}

EntServ

<?=$objResult[FilesID];?>

งงคำถาม แต่เอาต้องการแบบนี้รึเปล่า
รับทำระบบ Streaming Server อยากได้เว็บสตรีมมิ่งหล่อๆ ติดต่อ PM ครับ

rokaisakkon

if($product_id == $objResult["FilesID"])
{
      $product_name = $objResult["FilesID"];
      $product_class = "air";
      $product_version = "air-123";
      $unit = "20";
      $priceperunit = "45000";

      $product_title = $product_name." ".$product_class." รุ่น ".$product_version; // นำชื่อสินค้า , ชื่อรุ่น , รหัสสินค้า มาต่อเข้าด้วยกัน
}
#วงการฟรีแลนซ์มันโหดน่ะครับ

gubaaball

อ้างถึงจาก: bankker6480 ใน 07 กุมภาพันธ์ 2013, 03:07:33
ไอตัวแดงๆคือผมจะเอา ข้อมูลจาก db เข้าไปเก็บค่าในนั้น ไม่ทราบว่าถูกไหมครับมี "" ครอบ :wanwan011:

if($product_id == "<?=$objResult["FilesID"];?>")
{
      $product_name = "<?=$objResult["Name"];?>";

      $product_class = "air";
      $product_version = "air-123";
      $unit = "20";
      $priceperunit = "45000";

      $product_title = $product_name." ".$product_class." รุ่น ".$product_version; // นำชื่อสินค้า , ชื่อรุ่น , รหัสสินค้า มาต่อเข้าด้วยกัน
}

ผิดครับไม่น่าจะจำเป็นต้องปิด/เปิด <??> อีกครับ และก็ " จะไม่สามารถครอบ " ได้ครับ

if($product_id == $objResult['FilesID']);
{
      $product_name = $objResult['Name'];

เป็นอย่างนี้น่ะครับ เพราะเข้าใจว่าโค้ดทั้งหมดเป็น php น่าจะมีการเปิด/ปิด ก่อนหน้าประโยค if นี้

MeenyFancy

#4
เอาตัวแดงๆ อออกก็ผ่านครับ

อ้างถึงจาก: bankker6480 ใน 07 กุมภาพันธ์ 2013, 03:07:33
if($product_id == "<?=$objResult["FilesID"];?>")
{
     $product_name = "<?=$objResult["Name"];?>";
     $product_class = "air";
     $product_version = "air-123";
     $unit = "20";
     $priceperunit = "45000";

     $product_title = $product_name." ".$product_class." รุ่น ".$product_version; // นำชื่อสินค้า , ชื่อรุ่น , รหัสสินค้า มาต่อเข้าด้วยกัน
}
Have a good trip.
[direct=http://petdeecare.com]สุนัขป่วย[/direct] [direct=http://petdeecare.com]แมวป่วย[/direct]
[direct=http://petdeecare.com]หนูป่วย[/direct] [direct=http://petdeecare.com]อาหารแมว[/direct] [direct=http://petdeecare.com]อาหารหมา[/direct]

nst_nk

if($product_id == $objResult["FilesID"])

ไม่ผ่านก็

if($product_id == $objResult['FilesID'])

  ◤◤ รับเขียนระบบต่างๆครับ เช่น ระบบ Shipping , ร้านค้าออนไลน์ , อสังหาริมทรัพย์ , ระบบจัดการหลังบ้านทุกประเภท  สอบถามได้ครับ Line : bigznst ◥◥

BOMEN

if($product_id == $objResult["FilesID"])
{
      $product_name = $objResult["Name"];
      $product_class = "air";
      $product_version = "air-123";
      $unit = "20";
      $priceperunit = "45000";

      $product_title = $product_name." ".$product_class." รุ่น ".$product_version; // นำชื่อสินค้า , ชื่อรุ่น , รหัสสินค้า มาต่อเข้าด้วยกัน
}

xvlnw.com

<?=$objResult["FilesID"];?>

เดิมทีมันหมายถึงการแสดงผลตัวแปล $objResult["FilesID"] ออกมา หรืออาจนิยามได้ว่า

<?php echo $objResult["FilesID"];?>

คราวนี้ที่ท่านเขียน มันเป็นการเขียนในเงื่อนไขของภาษา PHP ไม่ได้แสดงผลออกมาให้ผู้ใช้งานได้เห็น
เพราะฉะนั้น ไม่จำเป็นต้อง echo คือให้เปรียบเทียบด้วยตัวแปรเฉยๆ
และที่สำคัญ ไม่ต้องเปิด tag PHP ซ้ำใน tag PHP เดิม เพราะยังไงมันก็รันไม่ได้

เช่น

<?php
// Statement
..
..
<? ... ?>
...
...
// Statement
?>

แบบนี้ยังไงก็รันไม่ผ่านครับ
[direct=https://cloudhost.in.th/wordpress-hosting]ツ ⓌⓄⓇⒹⓅⓇⒺⓈⓈ ⒽⓄⓈⓉⒾⓃⒼ [/direct] :wanwan014:  :D
[direct=https://cloudhost.in.th/cloudhosting.html]Cloud Hosting[/direct] [direct=https://cloudhost.in.th/cloudvps.html]Cloud Server[/direct] [direct=https://cloudhost.in.th/vpshosting.html]Cloud VPS Hosting[/direct] [direct=https://cloudhost.in.th/windowsvps.html]Cloud Windows[/direct] Tel: 080-348-0843 LINE: ixvlnw

bankker6480

โค้ดเต็มๆมันประมาณนี้ครับ
if($product_id == 7)
{
      $product_name = "Sony";
      $product_class = "Vaio";
      $product_version = "VGN-CR35S/L";
      $unit = "50";
      $priceperunit = "40000";

      $product_title = $product_name." ".$product_class." รุ่น ".$product_version; // นำชื่อสินค้า , ชื่อรุ่น , รหัสสินค้า มาต่อเข้าด้วยกัน
}

แต่ผมจะแก้โดยเอาข้อมูลจาก database มาเช็ครับค่ามาจากหน้า index ครับ ไม่รู้จะได้หรือเปล่า
คือมันเป็นปุ่ม add to cart ครับ กดปุ๊ปแล้วมาหน้า order ครับ แต่ไม่รู้ว่า เอามาเช็ค if แล้วจะได้ไหมยังไม่ได้ลองครับ

โค้ดต้นแบบ index.php
<html>
<head>
<title>My Shop - หน้าแสดงรายการสินค้า</title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<script language="javascript">
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height=' h ',width=' w ',top=' TopPosition ',left=' LeftPosition ',scrollbars=' scroll ',resizable'
win = window.open(mypage,myname,settings)
}
</script>
<style>
BODY {
    FONT-FAMILY: Arial, Helvetica, sans-serif
}
</style>
</head>

<body>
<center><b><u><font size="5">สินค้าทั้งหมด</font></u></b></center><br><br>
<center>[ <a href="cart.php" onclick="NewWindow(this.href,'name','600','400','yes');return false">ตะกร้าสินค้า</a> ] [ <a href="manageorder.php">แสดงรายการคำสั่งซื้อ</a> ]</center>
<br><br>
<center>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="60%" id="AutoNumber1" height="149">
  <tr>
    <td width="35%" bgcolor="#CCCCFF" align="center" height="20"><b>
    <font color="#000080">ภาพสินค้า</font></b></td>
    <td width="51%" bgcolor="#CCCCFF" align="center" height="20"><b>
    <font color="#000080">รายละเอียดสินค้า</font></b></td>
    <td width="14%" bgcolor="#CCCCFF" align="center" height="20"><b>
    <font color="#000080">สั่งซื้อ</font></b></td>
  </tr>


  <tr>
    <td width="35%" align="center" height="128">
    <img border="0" src="images/macbookair.jpg" width="170" height="150">    </td>
<td width="51%" align="center" height="128">
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
      <tr>
        <td width="27%" align="right">
        <p align="right"><font size="2" color="#800000">
        รหัสสินค้า :</font></td>
        <td width="3%">&nbsp;</td>
        <td width="70%"><font size="2" color="#000080">5</font></td>
      </tr>
      <tr>
        <td width="27%" align="right">
        <p align="right"><font size="2" color="#800000">
        ชื่อสินค้า :</font></td>
        <td width="3%">&nbsp;</td>
        <td width="70%"><font size="2" color="#000080">Macbook air</font></td>
      </tr>
      <tr>
        <td width="27%" align="right">
        <font size="2" color="#800000">
        ชื่อรุ่น :</font></td>
        <td width="3%">&nbsp;</td>
        <td width="70%"><font size="2" color="#000080">air-123</font></td>
      </tr>
      <tr>
        <td width="27%" align="right">
        <font size="2" color="#800000">
        หมวดหมู่ :</font></td>
        <td width="3%">&nbsp;</td>
        <td width="70%"><font size="2" color="#000080">
Notebook / อื่นๆ</font></td>
      </tr>
      <tr>
        <td width="27%" align="right">
        <font size="2" color="#800000">ราคา
        :</font></td>
        <td width="3%">&nbsp;</td>
        <td width="70%"><font size="2" color="#000080">45,000.00 บาท/เครื่อง</font></td>
      </tr>
      <tr>
        <td width="27%" align="right">
        <font size="2" color="#800000">
        เหลือ :</font></td>
        <td width="3%">&nbsp;</td>
        <td width="70%"><font size="2" color="#000080">20 เครื่อง</font></td>
      </tr>
      <tr>
        <td width="27%" align="right">
        <font size="2" color="#800000">
        พิเศษ :</font></td>
        <td width="3%">&nbsp;</td>
        <td width="70%"><font size="2" color="#000080">แถม Adapter charge ไฟ</font></td>
      </tr>
    </table>
    </td>
    <td width="14%" align="center" height="128"><b>
    <font color="#000080"><a href="order.php?product_id=5" onclick="NewWindow(this.href,'name','600','400','yes');return false">[สั่งซื้อ]</a></font></b></td>
  </tr>



  <tr>
    <td width="35%" align="center" height="128">
    <img border="0" src="images/vaionb.jpg" width="170" height="150">    </td>
<td width="51%" align="center" height="128">
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
      <tr>
      <tr>
        <td width="27%" align="right">
        <p align="right"><font size="2" color="#800000">
        รหัสสินค้า :</font></td>
        <td width="3%">&nbsp;</td>
        <td width="70%"><font size="2" color="#000080">7</font></td>
      </tr>
        <td width="27%" align="right">
        <p align="right"><font size="2" color="#800000">
        ชื่อสินค้า :</font></td>
        <td width="3%">&nbsp;</td>
        <td width="70%"><font size="2" color="#000080">Sony Vaio</font></td>
      </tr>
      <tr>
        <td width="27%" align="right">
        <font size="2" color="#800000">
        ชื่อรุ่น :</font></td>
        <td width="3%">&nbsp;</td>
        <td width="70%"><font size="2" color="#000080">VGN-CR35S/L</font></td>
      </tr>
      <tr>
        <td width="27%" align="right">
        <font size="2" color="#800000">
        หมวดหมู่ :</font></td>
        <td width="3%">&nbsp;</td>
        <td width="70%"><font size="2" color="#000080">
Notebook / Sony</font></td>
      </tr>
      <tr>
        <td width="27%" align="right">
        <font size="2" color="#800000">ราคา
        :</font></td>
        <td width="3%">&nbsp;</td>
        <td width="70%"><font size="2" color="#000080">40,000.00 บาท/เครื่อง</font></td>
      </tr>
      <tr>
        <td width="27%" align="right">
        <font size="2" color="#800000">
        เหลือ :</font></td>
        <td width="3%">&nbsp;</td>
        <td width="70%"><font size="2" color="#000080">50 เครื่อง</font></td>
      </tr>
      <tr>
        <td width="27%" align="right">
        <font size="2" color="#800000">
        พิเศษ :</font></td>
        <td width="3%">&nbsp;</td>
        <td width="70%"><font size="2" color="#000080">แถม Window Seven (รุ่นทดลองใช้)</font></td>
      </tr>
    </table>
    </td>
    <td width="14%" align="center" height="128"><b>
    <font color="#000080"><a href="order.php?product_id=7" onclick="NewWindow(this.href,'name','600','300','yes');return false">[สั่งซื้อ]</a></font></b></td>
  </tr>
</table>
</center>
<br><br>
</body>
</html>


โค้ด order.php
<html>
<head>
<title>My Shop - สั่งซื้อสินค้า</title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<style>
BODY {
    FONT-FAMILY: Arial, Helvetica, sans-serif
}
</style>
<script language="JavaScript" type="text/javascript">
function checkform (form,units)
{
  if (form.qty.value == "") {
    alert( "โปรดกรอกจำนวนสินค้าที่สั่งซื้อด้วย" );
    form.qty.focus();
    return false ;
  }

  if (form.qty.value <= 0) {
     alert( "จำนวนที่จะสั่งซื้อต้องมากกว่าศูนย์" );
     form.qty.focus();
     return false ;
  }

  if (form.qty.value != "") {
    var val = form.qty.value;
    var chars = "0123456789";
    var len = val.length;
    var char = "";

    for (i=0; i<len; i  )
    {
         char = val.charAt(i);
         if (chars.indexOf(char)==-1)
        {
               alert("จำนวนสินค้าที่สั่งซื้อต้องเป็นเลขจำนวนเต็มบวกเท่านั้น");
               form.qty.focus();
               return false;
        }
    }
  }

  if (form.qty.value > units) {
     alert( "ไม่สามารถสั่งซื้อได้ : สินค้ามีจำนวนไม่เพียงพอ" );
     form.qty.focus();
     return false ;
  }

  return true ;
}
</script>
</head>
<?
$objConnect = mysql_connect("localhost","postfree_dbweb","www12345") or die("Error Connect to Database");
$objDB = mysql_select_db("postfree_dbweb");
mysql_query("SET NAMES UTF8");
mysql_db_query(postfree_dbweb,"SET NAME UTF8");
$strSQL = "SELECT * FROM files";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<body bgcolor="#CCCCCC">
<?php

 $product_id 
$_GET['product_id']; // รับรหัสสินค้าเข้ามา (ใช้แบบ GET เพราะส่งผ่าน Browser)

 // ในการประยุกต์ต่อ ณ จุดนี้ คุณควรจะเอา $product_id ไปทำการดึงรายละเอียดของสินค้าชนิดนั้นๆออกมาจากในฐานข้อมูลคลังสินค้า ว่า ชื่อสินค้า , ชื่อรุ่น , รหัสสินค้า , จำนวนคงเหลือ , ราคา , ... นั้นมีค่าเป็นอะไร
//  โดยจะเอาค่าพวกนี้ไปแสดงบนตะกร้าสินค้าด้วย


 // แต่ในตัวอย่างนี้ผมจะทำการกำหนดค่าให้เองตรงๆเลย ไม่ได้ไปดึงรายละเอียดสินค้าออกมาจากฐานข้อมูลคลังสินค้าแต่อย่างใด !! (ดังนั้น Code ด้านล่างไม่มีอะไรสำคัญ แค่กำหนดค่าให้ตรงๆเท่านั้น)

 
if($product_id == ["FilesID"])
 {
      
$product_name "<?=$objResult["Name"];?>
";
      $product_category = "<?=$objResult["Category"];?>";
      $unit = "20";
      $priceperunit = "<?=$objResult["Price"];?>";

      $product_title = $product_name." ".$product_category; // นำชื่อสินค้า , ชื่อรุ่น , รหัสสินค้า มาต่อเข้าด้วยกัน
}

if($product_id == 7)
{
      $product_name = "Sony";
      $product_class = "Vaio";
      $product_version = "VGN-CR35S/L";
      $unit = "50";
      $priceperunit = "40000";

      $product_title = $product_name." ".$product_class." รุ่น ".$product_version; // นำชื่อสินค้า , ชื่อรุ่น , รหัสสินค้า มาต่อเข้าด้วยกัน
}


?>

<? if($unit >0) { ?>
<center>
<!-- ใส่ URL ของไฟล์ cart.php ครับ -->
<form action="cart.php" method="post" onsubmit="return checkform(this,<? echo $unit; ?>);">

<input name="add" type="hidden" value="<? echo $product_title; ?>">
<input name="price" type="hidden" value="<? echo $priceperunit; ?>">
<input type="hidden" name="product_id" value="<?echo $product_id; ?>">

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border: 1px dashed #800000" bordercolor="#111111" width="90%" id="AutoNumber1">
  <tr>
    <td width="34%" style="border: 1px dashed #800000">
    <p align="right">จำนวนชิ้นที่จะซื้อ
    :&nbsp;&nbsp; </td>
    <td width="66%" style="border: 1px dashed #800000">&nbsp;&nbsp;<input name="qty" type="text" size="36" maxlength="5"></td>
  </tr>
  <tr>
    <td width="100%" colspan="2" style="border: 1px dashed #800000"><center><input type="submit" value="เพิ่มลงตะกร้าสินค้า" name="submit"></center></td>
  </tr>
</table>
</form>
</center>
<? }
else {
      echo "<center>
<table border="1" style="border-style:dotted; border-collapse: collapse; padding-left:4; padding-right:4; padding-top:1; padding-bottom:1" bordercolor="#111111" width="75%" id="AutoNumber1" height="138">
  <tr>
    <td height="136">
    <center>
    <font size="5" color="#000080">ขออภัยสินค้าหมด</font><br>
    </center>   
    </td>
  </tr>
</table>
</center><br>";
}
?>
</body>
</html>



gubaaball

#9
ผมว่าทุกท่านตอบไปหมดแล้วน่ะครับ ถ้าเอาโค้ดที่ท่านโพสมารัน รับรอง error แน่นอนครับ เหตุผลก็มาจากหลายท่านที่ว่ามา  :P