Tue 27 Jun 2006 00:00:52
จากข้อมูลข้างล่างนี้จะให้มีการคำนวณดังนี้คือ แถว 1 เป็น table แถวที่ 2-5 เป็นผลลัพธ์ที่มีคนมาเล่นกินกิจกรรม แล้วทำการเลือกช้อย ต่างๆ เช่น
1 team11 team12 team13 team14 team21 poll poll4 team51
2 wc21 wc5 wc17 wc1 wc1 2 2 wc5
3 wc1 wc9 wc21 wc29 wc21 2 3 wc21
4 wc5 wc21 wc25 wc17 wc21 2 3 wc21
5 wc1 wc21 wc5 wc25 wc1 1 4 wc21
โดยจาก team11 -> team 14 จะเป็นข้อที่ 1 เป็นผลจากการที่สมาชิกมาร่วมกิจกรรมแล้วเลือกช้อยมา แล้วก็ add ลงดาต้าเบส ซึ่ง ค่า w มีค่าตั้งแต่ w1-w32 ผมอยากให้มันคำนวนโดยเอาค่ามาบวกกัน โดยในข้อที่ 1 team11-team14 ซึ่งแต่ะละ team จะมีให้เลือก 32 ชื่อ
ข้อที่ 1 (team11 -> team 14 ) อยากให้มีการคำนวณว่า ถ้าใครตอบ wc21,wc5,wc17,wc1 ให้ข้อละ 0.5 คะแนน แต่ถ้านอกเหนือจากนี้ คือ เป็น 0 แต้ม ถ้าตอบถูก 3 ข้อ ก็ให้ไป 1.5 แต้ม โดย ในข้อที่ 1 จะสลับคำตอบกันก็ได้ โดยไม่ต้องเรียงลำดับของคำตอบ ขอแค่ให้มีคำตอบดังนี้ wc21,wc17,wc1,wc5
ข้อที่ 2 เป็น Table = team21 กำหนดให้ว่า คำตอบที่ถูกต้อง คือ wc21 ใครที่ตอบคำตอบนี้ให้ 2 คะแนน แต่ถ้าตอบอย่างอื่นให้แต้มเป็น 0
ข้อที่ 3 เป็น Table = poll กำหนดให้ว่า คำตอบที่ถูกต้อง คือ 2 ใครที่ตอบคำตอบนี้ให้ 2 คะแนน แต่ถ้าตอบอย่างอื่นให้แต้มเป็น 0
ข้อที่ 4 เป็น Table = poll4 กำหนดให้ว่า คำตอบที่ถูกต้อง คือ 3 ใครที่ตอบคำตอบนี้ให้ 2 คะแนน แต่ถ้าตอบอย่างอื่นให้แต้มเป็น 0
ข้อที่ 5 เป็น Table = team51 กำหนดให้ว่า คำตอบที่ถูกต้อง คือ wc5 ใครที่ตอบคำตอบนี้ให้ 2 คะแนน แต่ถ้าตอบอย่างอื่นให้แต้มเป็น 0
จากนั้นเมื่อได้ค่าทั้งหมดแล้ว เอาผลลัพท์ในแต่ละข้อมารวมคะแนนกันกัน โดยจะมีคะแนน เต็ม 10 แล้วจากนั้นให้เรียงลำดับว่าให้ได้คะแนนสูงสุดอยู่บนสุด
คือผมลองทำแล้ว มันคำนวณไม่ได้ตามที่คิดไว้อ่ะครับ เลยมาขอคำแนะนำอีกที ยังไงรบกวนด้วยนะครับ เพราะผมต้องรีบทำให้เสร็จไม่งั้นแย่แน่เลยครับ
$total = "";
//ประกาศข้อที่ถูกไว้เป็น array
$correct = array("wc21", "wc5", "wc17", "wc1");
//ทำการ query เอาข้อมูลทั้งหมดออกมา
while($row = mysql_fetch_array($res, MYSQL_ASSOC)){
$choose = array($row["team11"], $row["team12"], $row["team13"], $row["team14"]);
$total[$row["id"]] += count(array_intersect($correct, $choose)) * 0.5; //คำนวณแต้มของข้อ 1
if($row["team21"] == "wc21") { $total[$row["id"]] += 2; }
if($row["poll"] == 2) { $total[$row["id"]] += 2; }
if($row["poll4"] == 3) { $total[$row["id"]] += 2; }
if($row["team51"] == "wc5") { $total[$row["id"]] += 2; }
}
จะได้ตัวแปร total ที่เป็น array โดยมี key เป็น id ของ user (ในกรณีที่แต่ละ record มี id กำกับ) ส่วนค่าภายใน array นั้นก็คือคะแนนที่ได้ครับ
Tue 27 Jun 2006 08:17:53
ขอบคุณครับ เดี๋ยวผมจะลองทำดูว่าผลจะเป็นยังไง ถ้ามีปัญหาสงสัยอะไรจะรบกวนใหม่นะครับ
Tue 27 Jun 2006 10:24:22
มีข้อความขึ้น error ครับ ไม่ทราบเป็นเพราะอะไรขึ้นแบบนี้
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\appserv\www\web\wc\list.php on line 19
ซึ่งบรรทัด 19 คือ while($row = mysql_fetch_array($res, MYSQL_ASSOC)){
จากดาต้าเบสที่จะให้คำนวณ
//ทำการ query เอาข้อมูลทั้งหมดออกมา
while($row = mysql_fetch_array($res, MYSQL_ASSOC)){
$choose = array($row["team11"], $row["team12"], $row["team13"], $row["team14"]);
$total[$row["id"]] += count(array_intersect($correct, $choose)) * 0.5; //คำนวณแต้มของข้อ 1
if($row["team21"] == "wc21") { $total[$row["id"]] += 2; }
if($row["poll"] == 2) { $total[$row["id"]] += 2; }
if($row["poll4"] == 3) { $total[$row["id"]] += 2; }
if($row["team51"] == "wc5") { $total[$row["id"]] += 2; }
}
$row1 = query("SELECT * FROM activity011_wc_2006 WHERE 1 LIMIT $start,$pp");
$cnt = fetchs(query("SELECT COUNT(no) as c FROM activity011_wc_2006 WHERE 1"));
$i = 0;
while ($r = fetchs($row1)){
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"total" => $r[total],
"time" => date("j M y H:i",$r[time]),
 
);
}
การวางแบบนี้ถูกหลักหรือเปล่าครับ พอผมวางแบบนี้
$row1 = query("SELECT * FROM wc_2006 WHERE 1 LIMIT $start,$pp");
$cnt = fetchs(query("SELECT COUNT(no) as c FROM wc_2006 WHERE 1"));
//ทำการ query เอาข้อมูลทั้งหมดออกมา
while($row = mysql_fetch_array($res, MYSQL_ASSOC)){
$choose = array($row["team11"], $row["team12"], $row["team13"], $row["team14"]);
$total[$row["id"]] += count(array_intersect($correct, $choose)) * 0.5; //คำนวณแต้มของข้อ 1
if($row["team21"] == "wc21") { $total[$row["id"]] += 2; }
if($row["poll"] == 2) { $total[$row["id"]] += 2; }
if($row["poll4"] == 3) { $total[$row["id"]] += 2; }
if($row["team51"] == "wc5") { $total[$row["id"]] += 2; }
}
$row1 = query("SELECT * FROM wc_2006 WHERE 1 LIMIT $start,$pp");
$cnt = fetchs(query("SELECT COUNT(no) as c FROM wc_2006 WHERE 1"));
$i = 0;
while ($r = fetchs($row1)){
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"total" => $r[total],
"time" => date("j M y H:i",$r[time]),
 
);
}
$i = 0;
while ($r = fetchs($row1)){
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"total" => $r[total],
"time" => date("j M y H:i",$r[time]),
 
);
}
มันก็จะขึ้น error แบบเดิมอีก
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\appserv\www\web\wc\list.php on line xxx
แบบนี้เป็นเพราะอะไรครับ
fetchs() เป็นฟังก์ชั้นที่มีการคืนค่าเป็นอะไรครับ
Tue 27 Jun 2006 15:35:07
query() ไม่ทราบว่าเป็นฟังก์ชั่นที่มีการคืนค่ามาเป็นอะไรครับ
fetchs() เป็นฟังก์ชั้นที่มีการคืนค่าเป็นอะไรครับ
ไม่ค่อยเข้าใจครับ กะคำถามข้างบนครับ คืนค่ายังไงเอ่ย เป็นตัวเลขหรือ ยังไงอ่ะครับ ผมไม่ค่อยถนัดซักเท่าไหร่ครับ
อิ ๆ งั้นผมอธิบายในส่งที่ผมอยากให้โชว์นะครับ
เป็นสคริปดึงข้อมูลมาจากดาต้าเบสและนำข้อมูลมาโชว์ในตาราง
$row1 = query("SELECT * FROM wc_2006 WHERE 1 LIMIT 10");
$i = 0;
while ($r = fetchs($row1)){
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"team11" => $r[team11],
"team12" => $r[team12],
|
|
"time" => date("j M y H:i",$r[time]),
 
);
}
// "total" => $r[total], ตรงนี้ของเดิมจะเป็น team11 team12 team13 team14 team21 poll poll4 team51
จะเรียงลงมาเรื่อย ๆ ครับ
ทีนี้ผมอยากได้คือ ให้คำนวณ เหมือนที่ผมได้เขียนลงไปแล้วอ่ะครับ โดยให้ผลจากการคำนวณทั้งหมดแล้วมาโชว์ใน ส่วนข้างล่างนี้ ตรง total
$i = 0;
while ($r = fetchs($row1)){
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"total" => $r[total],
"time" => date("j M y H:i",$r[time]),
 
);
}
ก็เลยจะถามว่า Code ที่คุณ admin ให้มาผมต้องใส่ตรงไหนอ่ะครับเพื่อให้ผลออกมาโชว์ใน "total" => $r[total], อ่ะครับ หรือต้องใส่เป็น "total" => $total,
เพราะโค้ดที่ให้มาเป็นแบบนี้
$total = "";
//ประกาศข้อที่ถูกไว้เป็น array
$correct = array("wc21", "wc5", "wc17", "wc1");
//ทำการ query เอาข้อมูลทั้งหมดออกมา
while($row1 = @mysql_fetch_array($res, MYSQL_ASSOC)){
$choose = array($row1["team11"], $row1["team12"], $row1["team13"], $row1["team14"]);
$total[$row1["id"]] += count(array_intersect($correct, $choose)) * 0.5; //คำนวณแต้มของข้อ 1
if($row1["team21"] == "wc21") { $total[$row["id"]] += 2; }
if($row1["poll"] == 2) { $total[$row1["id"]] += 2; }
if($row1["poll4"] == 3) { $total[$row1["id"]] += 2; }
if($row1["team51"] == "wc5") { $total[$row1["id"]] += 2; }
//ประกาศข้อที่ถูกไว้เป็น array
$correct = array("wc21", "wc5", "wc17", "wc1");
//ทำการ query เอาข้อมูลทั้งหมดออกมา
$link = mysql_connect($host, $user, $pass);
mysql_select_db($dbname, $link);
$res = mysql_query("SELECT * FROM wc_2006 WHERE 1 LIMIT 10", $link);
while($row1 = @mysql_fetch_array($res, MYSQL_ASSOC)){
$choose = array($row1["team11"], $row1["team12"], $row1["team13"], $row1["team14"]);
$total[$row1["id"]] += count(array_intersect($correct, $choose)) * 0.5; //คำนวณแต้มของข้อ 1
if($row1["team21"] == "wc21") { $total[$row["id"]] += 2; }
if($row1["poll"] == 2) { $total[$row1["id"]] += 2; }
if($row1["poll4"] == 3) { $total[$row1["id"]] += 2; }
if($row1["team51"] == "wc5") { $total[$row1["id"]] += 2; }
}
mysql_free_result($res);
mysql_close($link);
Tue 27 Jun 2006 16:32:30
ยังไม่ได้เหมือนเดิมครับงั้น ดูโค้ดทั้งหมดเลยนะครับ
<?
$DEFINE_SITE = true;
include "../../../includes/common.php";
include "../../../includes/template.php";
$template = new template();
$v = initial($ck);
if (!$p || $p < 1){ $p = 1; }
$pp = 50;
$start = (int)($p -1)*$pp;
$row1 = query("SELECT * FROM wc_2006 WHERE 1 LIMIT $start,$pp");
$cnt = fetchs(query("SELECT COUNT(no) as c FROM wc_2006 WHERE 1"));
$i = 0;
while ($r = fetchs($row1)){
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"team11" => $r[team11],
"team12" => $r[team12],
|
|
"time" => date("j M y H:i",$r[time]),
 
);
}
$allpage = ceil($cnt[c] / $pp);
$syntax = $PHP_SELF;
$template->assign_vars(array(
"page" => pageresult($syntax,$pp,$allpage,$p),
"p" => $p,
"ap" => $allpage,
));
$template->set_filenames(array(
'body' => 'list.html',
));
$template->pparse('body');
?>
นี่เป็นโค้ดที่ให้โชว์ข้อมูลโดยที่ยังไม่ได้คำนวณครับ ยังไงรบกวนอีกรอบนะครับ
$total = "";
$correct = array("wc21", "wc5", "wc17", "wc1");
while ($r = fetchs($row1)){
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"total" => $r[total],
"time" => date("j M y H:i",$r[time]),
$choose = array($r[total]["team11"], $r[total]["team12"], $r[total]["team13"], $r[total]["team14"]);
$total[$r[mem_no]] += count(array_intersect($correct, $choose)) * 0.5; //คำนวณแต้มของข้อ 1
if($r[total]["team21"] == "wc21") { $total[$r[mem_no]] += 2; }
if($r[total]["poll"] == 2) { $total[$r[mem_no]] += 2; }
if($r[total]["poll4"] == 3) { $total[$r[mem_no]] += 2; }
if($r[total]["team51"] == "wc5") { $total[$r[mem_no]] += 2; }
}
ประมาณนี้ครับ
Tue 27 Jun 2006 16:56:33
ลองแล้วครับแต่ก็ error ยังไง รบกวนช่วยใส่โค้ดให้เต็ม ๆ ว่าใส่ตรงไหนบ้างอ่ะครับ ผมลอวางหลายอันแล้ว ก็ยังใช้ไม่ได้อีก อ่ะครับ อิ ๆ
Tue 27 Jun 2006 17:31:38
ใส่โค้ดตามที่เรียงมาเลยใช่ไหมครับ
Tue 27 Jun 2006 17:37:04
ผมลองแล้วมันจะขึ้น ทุกช่องว่า Array อะครับ
while ($r = fetchs($row1)){
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"total" => $r[total],
"time" => date("j M y H:i",$r[time]),
}
ถ้าสมมุติว่าเป็น $r[no] คุณลอง print_r($r[no]) ให้หน่อยครับว่ามีการแสดงโครงสร้างอย่างไร
Wed 28 Jun 2006 09:15:23
อันนี้เป็นโค้ดในการดึงดาต้าเบสมาโชว์นะครับ
$i = 0;
while ($r = fetchs($row1)){
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"team11" => $r[team11],
"team12" => $r[team12],
"team13" => $r[team13],
"team14" => $r[team14],
"team21" => $r[team21],
"poll" => $r[poll],
"poll4" => $r[poll4],
"team51" => $r[team51],
"time" => date("j M y H:i",$r[time]),
 
);
}
แล้วข้างล่างนี้ผมเอามาจากดาต้าเบส ซึ่ง no เป็นลำดับการเข้ามาเล่นกิจกรรมนะครับ mem_no เป็น ลำดับของสมาชิก mem_name เป็น display name ของสามาชิก ซึ่งการเล่นกิจกรรมนี้จะไปดึงดาต้าเบสของสมาชิกมาจาก table ของสมาชิกอีกที
จากโค้ดข้างล่าง เป็นโค้ดทั้งหมดของ template นี้
<?
$DEFINE_SITE = true;
include "../../../includes/common.php";
include "../../../includes/template.php";
$template = new template();
$v = initial($ck);
if (!$p || $p < 1){ $p = 1; }
$pp = 50;
$start = (int)($p -1)*$pp;
$row1 = query("SELECT * FROM wc_2006 WHERE 1 LIMIT $start,$pp");
$cnt = fetchs(query("SELECT COUNT(no) as c FROM wc_2006 WHERE 1"));
$i = 0;
while ($r = fetchs($row1)){
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"team11" => $r[team11],
"team12" => $r[team12],
"team13" => $r[team13],
"team14" => $r[team14],
"team21" => $r[team21],
"poll" => $r[poll],
"poll4" => $r[poll4],
"team51" => $r[team51],
"time" => date("j M y H:i",$r[time]),
 
);
}
$allpage = ceil($cnt[c] / $pp);
$syntax = $PHP_SELF;
$template->assign_vars(array(
"page" => pageresult($syntax,$pp,$allpage,$p),
"p" => $p,
"ap" => $allpage,
));
$template->set_filenames(array(
'body' => 'list.html',
));
$template->pparse('body');
?>
ส่วนการนำไปโชว์ผ่าน browser
{m.no}
{m.mno}
{m.name}
{m.team11}
|
|
{m.team51}
$total = "";
$correct = array("wc21", "wc5", "wc17", "wc1");
while ($r = fetchs($row1)){
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"team11" => $r[team11],
"team12" => $r[team12],
"team13" => $r[team13],
"team14" => $r[team14],
"team21" => $r[team21],
"poll" => $r[poll],
"poll4" => $r[poll4],
"team51" => $r[team51],
"time" => date("j M y H:i",$r[time]),
$choose = array($r["team11"], $r["team12"], $r["team13"], $r["team14"]);
$total[$r[mem_no]] += count(array_intersect($correct, $choose)) * 0.5; //คำนวณแต้มของข้อ 1
if($r["team21"] == "wc21") { $total[$r[mem_no]] += 2; }
if($r["poll"] == 2) { $total[$r[mem_no]] += 2; }
if($r["poll4"] == 3) { $total[$r[mem_no]] += 2; }
if($r["team51"] == "wc5") { $total[$r[mem_no]] += 2; }
}
Wed 28 Jun 2006 11:42:49
ลองแล้วครับผลลัพท์ไม่ออกครับ เพราะว่า ผมทำให้โค้ดรันอยู่ใน
<!-- BEGIN m -->
{m.color}
{m.no}
{m.mno}
{m.name}
{m.total}
<!-- END m -->
แต่ไม่แน่ใจว่าโค้ดนี้
$choose = array($r["team11"], $r["team12"], $r["team13"], $r["team14"]);
$total[$r[mem_no]] += count(array_intersect($correct, $choose)) * 0.5; //คำนวณแต้มของข้อ 1
if($r["team21"] == "wc21") { $total[$r[mem_no]] += 2; }
if($r["poll"] == 2) { $total[$r[mem_no]] += 2; }
if($r["poll4"] == 3) { $total[$r[mem_no]] += 2; }
if($r["team51"] == "wc5") { $total[$r[mem_no]] += 2; }
}
อยู่นอก $template->assign_block_vars('m',array(
หรือเปล่าอ่ะครับ มันเลยไม่ออก ต้องแก้ตรงไหนอีกไหมครับ
เพียงต้องการนำตัวแปร $r มาคำนวณเท่านั้นครับ
Wed 28 Jun 2006 12:00:54
อืม ลองแล้วก็ไม่มีอะไรเกิดขึ้นเลยครับ เงียบฉี่ แบบนี้ต้องเช็คตรงไหนอ่ะครับ ผมมึนหมดแล้ว เหอะ ๆ ยังไงรบกวนด้วยครับ ผมหมดปัญญาแล้ว
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"team11" => $r[team11],
"team12" => $r[team12],
"team13" => $r[team13],
"team14" => $r[team14],
"team21" => $r[team21],
"poll" => $r[poll],
"poll4" => $r[poll4],
"team51" => $r[team51],
"time" => date("j M y H:i",$r[time]),
}
ถ้าตามนี้ ตัวแปร r น่าจะเป็นตัวที่เก็บข้อมูลการเลือกของสมาชิกถูกต้องไหมครับ
ก็น่าจะได้เป็น
$i = 0;
$total = "";
$correct = array("wc21", "wc5", "wc17", "wc1");
while ($r = fetchs($row1)){
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"team11" => $r[team11],
"team12" => $r[team12],
"team13" => $r[team13],
"team14" => $r[team14],
"team21" => $r[team21],
"poll" => $r[poll],
"poll4" => $r[poll4],
"team51" => $r[team51],
"time" => date("j M y H:i",$r[time]),
$choose = array($r[team11], $r[team12], $r[team13], $r[team14]);
$total[$r[mem_no]] += count(array_intersect($correct, $choose)) * 0.5; //คำนวณแต้มของข้อ 1
if($r[team21] == "wc21") { $total[$r[mem_no]] += 2; }
if($r[poll] == 2) { $total[$r[mem_no]] += 2; }
if($r[poll4] == 3) { $total[$r[mem_no]] += 2; }
if($r[team51] == "wc5") { $total[$r[mem_no]] += 2; }
}
จากนั้นลอง print_r($total) ดูครับว่ามีค่าใดๆไหมครับ
Wed 28 Jun 2006 14:30:05
<!-- BEGIN m -->
<tr bgcolor="{m.color}">
<td width="52">{m.no}</td>
<td width="96">{m.mno}</td>
<td width="139">{m.name}</td>
<td width="120" align="center">{m.total}<td>
</tr>
<!-- END m -->
อ่ะครับ ไม่เคยทำอะครับ
Thu 29 Jun 2006 14:45:07
ลองแล้วครับ ไม่มีผลอะไรออกมาเลยครับ ลองหลายรอบแล้ว พอจะมีวิธีอื่น อีกไหมครับ แบบว่า โค้ดยาวหน่อยไม่เป็นเอาแค่ว่า ใช้งานได้ก็พอครับ
$i = 0;
$total = "";
$correct = array("wc21", "wc5", "wc17", "wc1");
while ($r = fetchs($row1)){
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"team11" => $r[team11],
"team12" => $r[team12],
"team13" => $r[team13],
"team14" => $r[team14],
"team21" => $r[team21],
"poll" => $r[poll],
"poll4" => $r[poll4],
"team51" => $r[team51],
"time" => date("j M y H:i",$r[time]),
print_r($r);
$choose = array($r[team11], $r[team12], $r[team13], $r[team14]);
$total[$r[mem_no]] += count(array_intersect($correct, $choose)) * 0.5;
if($r[team21] == "wc21") { $total[$r[mem_no]] += 2; }
if($r[poll] == 2) { $total[$r[mem_no]] += 2; }
if($r[poll4] == 3) { $total[$r[mem_no]] += 2; }
if($r[team51] == "wc5") { $total[$r[mem_no]] += 2; }
}
echo "แสดงคะแนนของสมาชิก";
print_r($total);
ลองตรวจสอบด้วยครับว่าในโค๊ดเดิมนั้นมีการใช้งานตัวแปร $total อยู่หรือไม่ครับ
ส่วนที่ print_r($r); ใน loop while นั้น อยากให้ลองตรวจสอบครับว่ามีข้อมูลใดๆหรือไม่
ถ้าโค๊ดทำงานได้ครบถ้วนจะมีการแสดงคะแนนของสมาชิกด้วยครับ
Fri 30 Jun 2006 10:09:07
ใช้ได้แล้วครับ ขอบคุณมาก ๆ เลยครับ แต่ผลมันออกมาแบบนี้อ่ะครับ
Array ( [10] => 6 [804] => 5 [7366] => 1.5 [4284] => 7.5 [5040] => 3 [8796] => 5 [3822] => 9 [4392] => 3.5 [5222] => 3.5 [3991] => 1.5 [73] => 2 [16314] => 3.5 [41] => 4 [3095] => 4 [15772] => 3 [19021] => 3.5 [13020] => 3.5 [212] => 5.5 [8417] => 1.5 [8234] => 3.5 [8398] => 1 [8680] => 3 [3722] => 1.5 [5135] => 5 [2204] => 5 [890] => 7.5 [5838] => 5 [807] => 3.5 [18932] => 5 [6092] => 3.5 )
ไม่ทราบว่ามีวิธีแก้ไขไหมเอ่ย เพราะผมจะให้มันมาโชว์ในช่องข้างล่างนี้อ่ะครับ และผลของการคำนวณมามันจะมาอยู่ด้านบนแบบข้างล่างนี้อ่ะครับ
Array ( [10] => 6 [804] => 5 [7366] => 1.5 [4284] => 7.5 [5040] => 3 [8796] => 5 [3822] => 9 [4392] => 3.5 [5222] => 3.5 [3991] => 1.5 [73] => 2 [16314] => 3.5 [41] => 4 [3095] => 4 [15772] => 3 [19021] => 3.5 [13020] => 3.5 [212] => 5.5 [8417] => 1.5 [8234] => 3.5 [8398] => 1 [8680] => 3 [3722] => 1.5 [5135] => 5 [2204] => 5 [890] => 7.5 [5838] => 5 [807] => 3.5 [18932] => 5 [6092] => 3.5 )
|
ตอนนี้กะลังแก้อยู่ครับ ยังไงถ้ามีอะไรแนะนำอีก รบกวนอีกครั้งด้วยครับ
print_r($total);
print_r($r);
ในโค๊ดข้างบนออกครับ
Fri 30 Jun 2006 11:05:58
ลองแล้วครับ มันดึงฐานข้อมูลมาหมดเลยคับ
แสดงคะแนนของสมาชิก
Array ( [10] => 6 [804] => 5 [7366] => 1.5 [4284] => 7.5 [5040] => 3 [8796] => 5 [3822] => 9 [4392] => 3.5 [5222] => 3.5 [3991] => 1.5 [73] => 2 [16314] => 3.5 [41] => 4 [3095] => 4 [15772] => 3 [19021] => 3.5 [13020] => 3.5 [212] => 5.5 [8417] => 1.5 [8234] => 3.5 [8398] => 1 [8680] => 3 [3722] => 1.5 [5135] => 5 [2204] => 5 [890] => 7.5 [5838] => 5 [807] => 3.5 [18932] => 5 [6092] => 3.5 )
รายชื่อผู้เข้าร่วมกิจกรรม ตอนนี้ผลรวมยังไม่ออกนะครับ
แล้วมันก็ขึ้นมาเยอะกว่าที่ก็อบมาอ่ะครับ เป็นเพราะอะไรเอ่ย |
$i = 0;
$total = "";
$correct = array("wc21", "wc5", "wc17", "wc1");
while ($r = fetchs($row1)){
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"team11" => $r[team11],
"team12" => $r[team12],
"team13" => $r[team13],
"team14" => $r[team14],
"team21" => $r[team21],
"poll" => $r[poll],
"poll4" => $r[poll4],
"team51" => $r[team51],
"time" => date("j M y H:i",$r[time]),
);
$choose = array($r[team11], $r[team12], $r[team13], $r[team14]);
$total[$r[mem_no]] += count(array_intersect($correct, $choose)) * 0.5;
if($r[team21] == "wc21") { $total[$r[mem_no]] += 2; }
if($r[poll] == 2) { $total[$r[mem_no]] += 2; }
if($r[poll4] == 3) { $total[$r[mem_no]] += 2; }
if($r[team51] == "wc5") { $total[$r[mem_no]] += 2; }
}
คุณสามารถใช้งานตัวแปร $total ได้เลยครับ โดย echo $total[รหัสสมาชิก]; จะได้คะแนนครับ
Fri 30 Jun 2006 13:40:26
ลองหลายรอบแล้วครับ มันก็ยังไม่อยู่ในตารางอยู่ดีอ่ะครับ ข้างล่างเป็นโค้ดในการนำข้อมูลออกโชว์อ่ะครับ
<!-- BEGIN m -->
{m.color}
{m.no}
{{m.mno}
{m.name}
{m.total}
<!-- END m -->
ต้องใส่คลิ๊ปยังไง มันถึงจะมาโชว์ที่ {m.total} อ่ะครับ มึนอีกรอบแล้ว
$i = 0;
$correct = array("wc21", "wc5", "wc17", "wc1");
while ($r = fetchs($row1)){
$total = 0;
$choose = array($r[team11], $r[team12], $r[team13], $r[team14]);$total[$r[mem_no]] += count(array_intersect($correct, $choose)) * 0.5;
if($r[team21] == "wc21") { $total[$r[mem_no]] += 2; }
if($r[poll] == 2) { $total[$r[mem_no]] += 2; }
if($r[poll4] == 3) { $total[$r[mem_no]] += 2; }
if($r[team51] == "wc5") { $total[$r[mem_no]] += 2; }
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"team11" => $r[team11],
"team12" => $r[team12],
"team13" => $r[team13],
"team14" => $r[team14],
"team21" => $r[team21],
"poll" => $r[poll],
"poll4" => $r[poll4],
"team51" => $r[team51],
"time" => date("j M y H:i",$r[time]),
"total" => $total,
}
น่าจะประมาณนี้ครับ
Fri 30 Jun 2006 15:09:37
ลองแล้วมัน error ครับ แบบนี้เลย
Warning: Cannot use a scalar value as an array in c:\appserv\www\web\online-stationv1\event\2006\wc\list.php on line 27
แล้วก็ error ซ้ำ ๆ กันด้วย แต่ขึ้นข้อความ Warning: Cannot use a scalar value as an array in
แล้วในช่องตาราง ขึ้น 0
|
เป็นเพราะอะไรเอ่ย
$i = 0;
$correct = array("wc21", "wc5", "wc17", "wc1");
while ($r = fetchs($row1)){
$total = 0;
$choose = array($r[team11], $r[team12], $r[team13], $r[team14]);$total += count(array_intersect($correct, $choose)) * 0.5;
if($r[team21] == "wc21") { $total += 2; }
if($r[poll] == 2) { $total += 2; }
if($r[poll4] == 3) { $total += 2; }
if($r[team51] == "wc5") { $total += 2; }
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"team11" => $r[team11],
"team12" => $r[team12],
"team13" => $r[team13],
"team14" => $r[team14],
"team21" => $r[team21],
"poll" => $r[poll],
"poll4" => $r[poll4],
"team51" => $r[team51],
"time" => date("j M y H:i",$r[time]),
"total" => $total,
}
น่าจะประมาณนี้ล่ะครับ
Fri 30 Jun 2006 15:48:14
โอ้ว สุดยอดเลยครับ ได้แล้ว ๆๆ รอดตายอีกทีครับ ขอบพระคุณมั๊ก ๆ จริง ๆ ขอบคุณอย่างใจจริง เลยครับ ท่านเก่งอย่างเหลือเชื่อ เหอะ ๆ ชอบเว็บนี้จริง ๆ เลยท่าน ที่ช่วยแก้ปัญหามาตลอด เลยครับ
อิ ๆ
Mon 3 Jul 2006 11:02:22
ขอเพิ่มเติมอีกนิดนึงครับ ถ้าจะเอาผลจาก total มาเรียงลำดับจากมากไปน้อยต้องใช้สคริปยังไงอ่ะครับ
<!-- BEGIN m -->
{m.color}
{m.no}
{m.mno}
{m.name}
{m.total}
<!-- END m -->
ที่ใช้แสดงผลด้วยครับ
Mon 3 Jul 2006 12:58:28
มีแค่นี้แหละครับ ตั้งเป็นชื่อ list.html
<!-- BEGIN m -->
{m.color}
{m.no}
{m.mno}
{m.name}
{m.total}
<!-- END m -->
ส่วนโค้ดที่จะทำให้ไปโชว์หน้า list.html ดังข้างล่างครับ เป็นไฟล์ชื่อ list.php
<?
$DEFINE_SITE = true;
include "../../../includes/common.php";
include "../../../includes/template.php";
$template = new template();
$v = initial($ck);
if (!$p || $p < 1){ $p = 1; }
$pp = 23;
$start = (int)($p -1)*$pp;
$row1 = query("SELECT * FROM wc_2006 WHERE 1 LIMIT $start,$pp ");
$cnt = fetchs(query("SELECT COUNT(no) as c FROM wc_2006 WHERE 1 "));
// ตัวแปร r น่าจะเป็นตัวที่เก็บข้อมูลการเลือกของสมาชิก
$i = 0;
$correct = array("wc1", "wc16", "wc17", "wc25");
while ($r = fetchs($row1)){
$total = 0;
$choose = array($r[team11], $r[team12], $r[team13], $r[team14]);
$total += count(array_intersect($correct, $choose)) * 0.5;
if($r[team21] == "") { $total += 2; }
if($r[poll] == "") { $total += 2; }
if($r[poll4] == "3") { $total += 2; }
if($r[team51] == "") { $total += 2; }
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$template->assign_block_vars('m',array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"team11" => $r[team11],
"team12" => $r[team12],
"team13" => $r[team13],
"team14" => $r[team14],
"team21" => $r[team21],
"poll" => $r[poll],
"poll4" => $r[poll4],
"team51" => $r[team51],
"time" => date("j M y H:i",$r[time]),
"total" => $total,
 
);
}
$allpage = ceil($cnt[c] / $pp);
$syntax = $PHP_SELF;
$template->assign_vars(array(
"page" => pageresult($syntax,$pp,$allpage,$p),
"p" => $p,
"ap" => $allpage,
"total" => $total,
));
$template->set_filenames(array(
'body' => 'list.html',
));
$template->pparse('body');
?>
Tue 4 Jul 2006 13:32:23
ไม่ทราบว่าทดสอบเป็นไงบ้างครับ เหอะ ๆ รอความหวังอยู่อ่ะ
$i = 0;
$correct = array("wc21", "wc5", "wc17", "wc1");
$pointList = "";
while ($r = fetchs($row1)){
$total = 0;
$choose = array($r[team11], $r[team12], $r[team13], $r[team14]);$total += count(array_intersect($correct, $choose)) * 0.5;
if($r[team21] == "wc21") { $total += 2; }
if($r[poll] == 2) { $total += 2; }
if($r[poll4] == 3) { $total += 2; }
if($r[team51] == "wc5") { $total += 2; }
$color = ($color != "#FFFFFF" ? "#FFFFFF" : "#DFDFDF");
$pointList[$total][$r[mem_no]] = array(
"color" => $color,
"no" => $r[no],
"mno" => $r[mem_no],
"name" => $r[mem_name],
"team11" => $r[team11],
"team12" => $r[team12],
"team13" => $r[team13],
"team14" => $r[team14],
"team21" => $r[team21],
"poll" => $r[poll],
"poll4" => $r[poll4],
"team51" => $r[team51],
"time" => date("j M y H:i",$r[time]),
"total" => $total,
}
ksort($pointList);
foreach($pointList as $v){
foreach($v as $val){
$template->assign_block_vars('m',$val);
}
}
ลองแบบนี้ดูครับ







