Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > ASP > ASP Forum > array ดึงข้อมูลจากฐานมาแสดง รบกวนหน่อยนะคะคือต้องการค่าจากฐานข้อมูล 4 อย่างคือ



 

array ดึงข้อมูลจากฐานมาแสดง รบกวนหน่อยนะคะคือต้องการค่าจากฐานข้อมูล 4 อย่างคือ

 



Topic : 036885



โพสกระทู้ ( 64 )
บทความ ( 0 )



สถานะออฟไลน์




รบกวนหน่อยนะคะคือต้องการค่าจากฐานข้อมูล 4 อย่างคือ
[id],[title],[price],[picture] ออกมาเป็น array คะทำอย่างไร



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-01-12 10:50:45 By : jyp View : 1698 Reply : 4
 

 

No. 1



โพสกระทู้ ( 538 )
บทความ ( 3 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


เข้าใจว่าค่าใน tabe ของทั้ง 4 column จะเป็น string ทั้งหมดแหละเนาะ

อย่างนี้เปล่าที่ต้องการ
dim Product(4) as string

Product(0) = rec.field("ID").value
Product(1) = rec.field("title").value
Product(2) = rec.field("price").value
Product(3) = rec.field("picture").value







Date : 2010-01-12 11:22:33 By : salapao_codeman
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

หรือไม่ลองใช้ Array 2 มิติน่ะครับ

Code
Dim arr(10,1)
arr(0,0) = ww
arr(0,1) = xx
arr(1,0) = yy
arr(1,1) = zz
.
.
.
For i = 0 To UBound(arr)
Response.write arr(i,0) & "-" arr(i,1)
Next

Date : 2010-01-12 18:36:33 By : webmaster
 

 

No. 3

Guest


ปัญหามีอยู่ว่า ค่าในfunction function GetAllProductList(Plist) ไม่ยอมส่งค่าที่บันทึกข้อมูลมาแสดงคะ
ตรง
for (var i = 0; i < allResult.length-1; i++){

ติดปัญหานี่นานและช่วยหน่อยคะ
aaa
พอ alert ค่าออกมาก็มีส่งมาคะ
bbb

cccc



///// connect.asp/////////
<%
set con =server.CreateObject("adodb.connection")
con.ConnectionString ="Provider=SQLOLEDB.1;Initial Catalog=Test;Data Source=Test;user id=sa;PASSWORD=Test"
con.Open
%>
//// end///
///////// ///////////
<!--#include file =connect.asp -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv='content-type' content='text/html' charset='windows-874'>
<title>การจัดการสินค้าคงคลังด้วย AJAX </title>
<link rel="stylesheet" type="text/css" href="Style.css" >
<script type="text/javascript">
var xmlHttp;
var number;
var Pid;
var title;
var result;
var price;
var picture;

function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}

//เริ่มส่วนแสดงรายการสินค้า
function listProduct() {
var AllProductList = document.getElementById("AllProductList");
while(AllProductList.childNodes.length > 0) {
AllProductList.removeChild(AllProductList.childNodes[0]);
}
var url = "ListProduct.asp";
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleListStateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}

function handleListStateChange() {

if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
Plist = xmlHttp.responseText;
GetAllProductList(Plist);
}
else {
alert("พบข้อผิดพลาดในการแสดงข้อมูล");
}
}
}

function GetAllProductList(Plist) {
createHeadTable();
// var allResult=new Array();
allResult=Plist.split(",");
alert(allResult);
alert(allResult.length);
for (var i = 0; i < allResult.length-1; i++){
var result=allResult[i].split(":");
var row = document.createElement("tr");
var number = i+1;
var Pid = result[0];
var title = result[1];
var price = result[2];
var picture = result[3];
updateAllProductList(number, Pid, title, price, picture);
}
}

function createHeadTable() {
var row = document.createElement("tr");
row.appendChild(createCellWithText("ลำดับที่"));
row.appendChild(createCellWithText("ชื่อสินค้า"));
row.appendChild(createCellWithText("ราคา"));
row.appendChild(createCellWithText("รูปสินค้า"));
row.appendChild(createCellWithText("ลบสินค้า"));
row.appendChild(createCellWithText("ปรับปรุงสินค้า"));
row.style.background = "#ffcc99";
row.style.border = "0";

document.getElementById("AllProductList").appendChild(row);
updateProductListVisibility();
}

function updateAllProductList(number, Pid, title, price, picture) {
alert(number, Pid, title, price, picture);
var row = document.createElement("tr");
row.appendChild(createCellWithText(number));
row.appendChild(createCellWithText(title));
row.appendChild(createCellWithText(price));
row.appendChild(createCellWithText(picture));

var deleteButton = document.createElement("input");
deleteButton.setAttribute("type", "button");
deleteButton.setAttribute("value", "ลบสินค้า");
deleteButton.onclick = function () { deleteProduct(Pid); };

var updateButton = document.createElement("input");
updateButton.setAttribute("type", "button");
updateButton.setAttribute("value", "ปรับปรุงสินค้า");
updateButton.onclick = function () { updateInputBox(Pid, title, price, picture); };
celld = document.createElement("td");
celld.appendChild(deleteButton);
cellu = document.createElement("td");
cellu.appendChild(updateButton);
row.appendChild(celld);
row.appendChild(cellu);

document.getElementById("AllProductList").appendChild(row);
updateProductListVisibility();
}

function createCellWithText(text) {
var cell = document.createElement("td");
cell.appendChild(document.createTextNode(text));
return cell;
}

function updateProductListVisibility() {
var AllProductList = document.getElementById("AllProductList");
if(AllProductList.childNodes.length > 0) {
document.getElementById("AllProductList").style.display = "";
}
else {
document.getElementById("AllProductList").style.display = "none";
}
}

//เริ่มทำงานส่วนเพิ่มรายการสินค้า
function addProduct() {
Pid = document.getElementById("Pid").value;

if(Pid == ""){
title = document.getElementById("title").value;
price = document.getElementById("price").value;
picture = document.getElementById("picture").value;

if(title == "" || price == "" || picture == "") {
return;
}
var url = "AddProduct.asp?"+ createAddQueryString(title, price, picture);
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}else{
updateProduct();
}
}

// เริ่มทำงานส่วนปรับปรุงข้อมูลสินค้า
function updateInputBox(Pid, title, price, picture) {
document.getElementById("Pid").value = Pid;
document.getElementById("title").value = title;
document.getElementById("price").value = price;
document.getElementById("picture").value = picture;
}

function updateProduct() {
title = document.getElementById("title").value;
price = document.getElementById("price").value;
picture = document.getElementById("picture").value;

if(Pid == "" || title == "" || price == "" || picture == "") {
return;
}
var url = "UpdateProduct.asp?Pid=" + Pid +"&" + createAddQueryString(title, price, picture);
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}

function createAddQueryString(title, price, picture) {
var queryString = "title=" + title + "&price=" + price + "&picture=" + picture;
return queryString;
}

function handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
clearInputBoxes();
deleteListProduct();
listProduct();
}
else {
alert("พบข้อผิดพลาดในการบันทึกรายการสินค้า");
}
}
}

function clearInputBoxes() {
document.getElementById("Pid").value = "";
document.getElementById("title").value = "";
document.getElementById("price").value = "";
document.getElementById("picture").value = "";
}

//เริ่มทำงานในส่วนลบรายการสินค้า
function deleteProduct(Pid) {
var url = "deleteProduct.asp?Pid=" + Pid;
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleDeleteStateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}

function deleteListProduct() {
var AllProductList = document.getElementById("AllProductList");
while(AllProductList.childNodes.length > 0) {
AllProductList.removeChild(AllProductList.childNodes[0]);
}
}


function handleDeleteStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
clearInputBoxes();
deleteListProduct();
listProduct()
}
else {
alert("พบข้อผิดพลาดในการลบข้อมูล");
}
}
}

</script>
</head>
<body onload="listProduct();">
<table height='50' width='700' bgcolor='brown' >
<tr>
<td >
<p>การจัดการสินค้าคงคลัง</p>
</td>
</tr>
</table>
<form action="#">
<table width="80%" border="0" align="left">
<tr>
<td>ชื่อสินค้า: <input type="text" id="title" size="45"/><input type="hidden" id="Pid" /></td>
<td>ราคาสินค้า: <input type="text" id="price"/></td>
<td>รูปสินค้า: <input type="text" id="picture"/></td>
</tr>
<tr>
<td colspan="3" align="left">
<input type="button" value="บันทึก" onclick="addProduct();"/>
<input type="button" value="ยกเลิก" onclick="clearInputBoxes()"/>
</td>
</tr>
</table>
</form>
<br>
<br>
<br>
<br>
<h2>รายการสินค้าทั้งหมด</h2>
<table border="1" width="93%" >
<tbody id="AllProductList" ></tbody>
</table>
</body>
</html>
///////end///////

/////// ListProduct.asp //////
<!--#include file =connect.asp -->
<%
set rs1 =server.CreateObject("adodb.recordset")
sql1="select * from product_item order by id asc"
rs1.Open sql1,con,1,3
if not rs1.eof then
Response.Write(rs1.fields("id"))
Response.Write(rs1.fields("title"))
Response.Write(rs1.fields("price"))
Response.Write(rs1.fields("picture"))
end if
rs1.close

%>

///// End////

//// AddProduct.asp //////

<!--#include file =connect.asp -->
<%
set rs1 =server.CreateObject("adodb.recordset")
sql1 ="select * from product_item order by Id desc "
rs1.Open sql1,con,1,3
if not rs1.eof then
Id=rs1("id")+1
else
Id = 1
end if


title=Request.QueryString("title")
price=Request.QueryString("price")
picture=Request.QueryString("picture")

set rs2 =server.CreateObject("adodb.recordset")
sql2="select * from product_item"
rs2.Open sql2,con,1,3
' Response.Write(sq1)
rs2.addnew
rs2.fields("id")=id
rs2.fields("title")=title
rs2.fields("price")=price
rs2.fields("picture")=picture

rs2.update
rs2.close

%>
//// End////
Date : 2010-01-13 15:09:14 By : jyp
 


 

No. 4



โพสกระทู้ ( 64 )
บทความ ( 0 )



สถานะออฟไลน์


เง้อๆๆไม่มีคายตอบเยยอะ เศร้าใจมากๆเยยยยยย
Date : 2010-01-14 13:20:06 By : jyp
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : array ดึงข้อมูลจากฐานมาแสดง รบกวนหน่อยนะคะคือต้องการค่าจากฐานข้อมูล 4 อย่างคือ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่