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

หน้าที่นังไม่ได้ดึงข้อมูล

Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
</head>
<body>
<p> </p>
<?php
mysql_connect("localhost", "root", "test") or die(mysql_error());
mysql_select_db(testmember) or die(mysql_error());
$yesterday= "06.05.11";
$today="10.05.11";
$data = mysql_query("SELECT * FROM status WHERE datetime >='$yesterday' AND datetime<='$today'") or die(mysql_error());
print "<table width='100' border='1' cellpadding='0' cellspacing='0'>";
print "<td width='90' height='26' bgcolor='#99FF99'><div align='center'><strong>Nitrogen Tank No.</strong></div></td>";
print "</tr>";
for ($i = 1; $i <= 12; )
{
print "<tr height='33'>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>No.".$i."</strong></div></td>";
while($info = mysql_fetch_array( $data ))
{
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no.$i]."</strong></div></td>";
}
$i++;
}
print "</tr>";
print "</tr>";
print "</table>";
print "</body>";
?>
</html>
ส่วนนี่คือไฟล์ sqlCode (PHP)
-- phpMyAdmin SQL Dump
-- version 2.10.3
-- http://www.phpmyadmin.net
--
-- โฮสต์: localhost
-- เวลาในการสร้าง: 10 พ.ค. 2011 น.
-- รุ่นของเซิร์ฟเวอร์: 6.0.4
-- รุ่นของ PHP: 6.0.0-dev
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- ฐานข้อมูล: `testmember`
--
-- --------------------------------------------------------
--
-- โครงสร้างตาราง `status`
--
CREATE TABLE `status` (
`no1` varchar(14) NOT NULL,
`no2` varchar(14) NOT NULL,
`no3` varchar(14) NOT NULL,
`no4` varchar(14) NOT NULL,
`no5` varchar(14) NOT NULL,
`no6` varchar(14) NOT NULL,
`no7` varchar(14) NOT NULL,
`no8` varchar(14) NOT NULL,
`no9` varchar(14) NOT NULL,
`no10` varchar(14) NOT NULL,
`no11` varchar(14) NOT NULL,
`no12` varchar(14) NOT NULL,
`no13` varchar(14) NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`datetime` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- dump ตาราง `status`
--
INSERT INTO `status` VALUES ('Used', 'Empty', 'Spare', 'Empty', 'Empty', 'Empty', 'Used', 'Spare', 'Empty', '', '', '', '', '2011-05-06 13:49:51', '06.05.11');
INSERT INTO `status` VALUES ('Spare', 'Tank Damage', 'Empty', 'Spare', 'Spare', 'Spare', 'Spare', 'Used', 'Spare', 'Empty', 'Spare', 'Spare', '', '2011-05-09 17:50:09', '09.05.11');
INSERT INTO `status` VALUES ('Spare', 'Used', 'Tank Damage', 'Used', 'Used', 'Used', 'Used', 'Used', 'Spare', 'Used', 'Spare', 'Used', '', '2011-05-09 13:22:44', '09.05.11');
INSERT INTO `status` VALUES ('Spare', 'Tank Damage', 'Empty', 'Spare', 'Spare', 'Spare', 'Spare', 'Used', 'Spare', 'Empty', 'Spare', 'Spare', '', '2011-05-09 17:52:43', '09.05.11');
INSERT INTO `status` VALUES ('Used', 'Spare', 'Empty', 'Empty', 'Tank Damage', 'Used', 'Empty', 'Empty', 'Empty', 'Tank Damage', 'Empty', 'Used', '', '2011-05-10 12:33:02', '10.05.11');
INSERT INTO `status` VALUES ('Used', 'Spare', 'Empty', 'Empty', 'Tank Damage', 'Used', 'Empty', 'Empty', 'Empty', 'Tank Damage', 'Empty', 'Used', '', '2011-05-10 12:33:05', '10.05.11');
INSERT INTO `status` VALUES ('Used', 'Spare', 'Empty', 'Empty', 'Tank Damage', 'Used', 'Empty', 'Empty', 'Empty', 'Tank Damage', 'Empty', 'Used', '', '2011-05-10 12:33:09', '10.05.11');
INSERT INTO `status` VALUES ('Used', 'Spare', 'Empty', 'Empty', 'Tank Damage', 'Used', 'Empty', 'Empty', 'Empty', 'Tank Damage', 'Empty', 'Used', '', '2011-05-10 12:33:39', '10.05.11');
INSERT INTO `status` VALUES ('Used', 'Spare', 'Empty', 'Empty', 'Tank Damage', 'Used', 'Empty', 'Empty', 'Empty', 'Tank Damage', 'Empty', 'Used', '', '2011-05-10 12:33:41', '10.05.11');
INSERT INTO `status` VALUES ('Used', 'Spare', 'Empty', 'Empty', 'Tank Damage', 'Used', 'Empty', 'Empty', 'Empty', 'Tank Damage', 'Empty', 'Used', '', '2011-05-10 12:33:43', '10.05.11');
INSERT INTO `status` VALUES ('Used', 'Spare', 'Empty', 'Empty', 'Tank Damage', 'Used', 'Empty', 'Empty', 'Empty', 'Tank Damage', 'Empty', 'Used', '', '2011-05-10 12:33:48', '10.05.11');
INSERT INTO `status` VALUES ('Used', 'Spare', 'Empty', 'Empty', 'Tank Damage', 'Used', 'Empty', 'Empty', 'Empty', 'Tank Damage', 'Empty', 'Used', '', '2011-05-10 12:33:50', '10.05.11');
INSERT INTO `status` VALUES ('Used', 'Spare', 'Empty', 'Empty', 'Tank Damage', 'Used', 'Empty', 'Empty', 'Empty', 'Tank Damage', 'Empty', 'Used', '', '2011-05-10 12:33:52', '10.05.11');
INSERT INTO `status` VALUES ('Used', 'Spare', 'Empty', 'Empty', 'Tank Damage', 'Used', 'Empty', 'Empty', 'Empty', 'Tank Damage', 'Empty', 'Used', '', '2011-05-10 12:33:54', '10.05.11');
ช่วยแก้ให้หน่อยนะ
Tag : PHP, CakePHP

|
ประวัติการแก้ไข 2011-05-11 15:17:14 2011-05-11 15:22:31
|
 |
 |
 |
 |
Date :
2011-05-11 15:12:19 |
By :
sambeem001 |
View :
866 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ปัญหาน่าจะอยุ่ที่ SQL ตอนดึงข้อมูลมากกว่า ถ้าดึงได้ก็ไม่ยากแค่ใช้ While เรียกข้อมูลขึ้นมาแสดงในตารางที่สร้างแล้วแค่นั้นเอง
ลองดูอันนี้เป็นแนวทาง
Code (PHP)
<?PHP
include'connect.php';
$id=$_GET[id]; //echo $id;
if($id)
{
//-----------------------------หัวตาราง----------------------------------
echo "<table width=\"1000\" border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#999999\" bgcolor=\"#f8f8f8\">
<tr><td colspan='8' bgcolor=\"#CC9900\"><center>ตารางสรุปผลคะแนน</center></td></tr>
<tr><td width=\"50\" bgcolor=\"#CC9900\"><center><font size='2'>ลำดับที่</font></center></td>
<td width=\"500\" bgcolor=\"#CC9900\"><center><font size='2'>คำถาม</font></center></td>
<td width=\"200\" bgcolor=\"#CC9900\"><center><font size='2'>ข้อที่คุณตอบ</font></center></td>
<td width=\"200\" bgcolor=\"#CC9900\"><center><font size='2'>คำตอบที่ถูกต้อง</font></center></td>
<td width=\"70\" bgcolor=\"#CC9900\"><center><font size='2'>ข้อสอบชุดที่ </font></center></td>
<td width=\"70\" bgcolor=\"#CC9900\"><center><font size='2'>คะเเนนข้อนี้</font></center></td></tr>";
//----------------------------------------SQL เลือกข้อมูล------------------------------------------
$sql="select q_id,uid,select_ans,ans_user.true_ans,ans_user.dept,ans_user.level,question.question,ans1,ans2,ans3,ans4
from ans_user,question where ans_user.q_id=question.id and ans_user.uid='$id'";
//echo $sql;
$query=mysql_query($sql);
$num=mysql_num_rows($query);
//echo $num;
//if($num=='0') //{echo "ไม่มีรายการ !!";}
if($num=='0')
{
echo "<script type=\"text/javascript\">";
echo "alert(\"ไม่มีรายการ !!.... >>\");";
echo "window.history.back();";
echo "</script>";
exit();
}
$i=1;
while($record=mysql_fetch_array($query))
{
//---------------------------วนลูปแสดงข้อมูล---------------------------------
$id=$record[id]; //echo $id;
echo"<tr>";
echo "<td><font size=2><center>$record[q_id]</center></font></td>";
echo "<td><font size=2>$record[question]</font></td>";
if($record[select_ans]=='1')
{ echo "<td><font size=2>$record[ans1]</font></td>"; }
if($record[select_ans]=='2')
{ echo "<td><font size=2>$record[ans2]</font></td>"; }
if($record[select_ans]=='3')
{ echo "<td><font size=2>$record[ans3]</font></td>"; }
if($record[select_ans]=='4')
{ echo "<td><font size=2>$record[ans4]</font></td>"; }
if($record[true_ans]=='1')
{ echo "<td><font size=2>$record[ans1]</font></td>"; }
if($record[true_ans]=='2')
{ echo "<td><font size=2>$record[ans2]</font></td>"; }
if($record[true_ans]=='3')
{ echo "<td><font size=2>$record[ans3]</font></td>"; }
if($record[true_ans]=='4')
{ echo "<td><font size=2>$record[ans4]</font></td>"; }
echo "<td><font size=2><center>$record[level]</center></font></td>";
if($record[select_ans]==$record[true_ans])
{ echo "<td><font size=2><center>1</center></font></td>"; }
else
{ echo "<td><font size=2><center>0</center></font></td>"; }
echo "</tr>";
$i++;
}
echo "</table>";
mysql_close();
}
?>
|
 |
 |
 |
 |
Date :
2011-05-11 16:05:05 |
By :
pjnarubase |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|