|
|
|
ขอความช่วยเหลือเรื่องการจัดตารางหน่อยค่ะ <table>....</table> |
|
|
|
|
|
|
|
ตอนแรกเป็นแบบนี้
แต่ว่าอยากได้แบบนี้ค่ะ
คือลองจัดดูแล้ว... แต่จัดไปจัดมา มันเละมากเลยค่ะ T^T
ขอบคุณค่ะ ^^
Code (PHP)
<?php require_once('Connections/myconnection.php');
include("session.php");
include("header.php");
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_myconnection, $myconnection);
$query_Recordset1 = "SELECT service_fix FROM service";
$Recordset1 = mysql_query($query_Recordset1, $myconnection) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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=utf-8" />
<title>After Sale Service</title>
</head>
<body>
<center>
<p> </p>
<p> </p>
<p> </p>
<p>
<h3>รายงานสรุปการแจ้งซ่อมประจำเดือน
</h3>
<p> </p>
<form name="frmdata" method="post" action="month_report.php" >
<p>ค้นหา :
<select name="Month" id="Month">
<option value="01" <? if($Month=='01') echo " selected='selected'" ?> > มกราคม</option>
<option value="02" <? if($Month=='02') echo " selected='selected'" ?> > กุมภาพันธ์</option>
<option value="03" <? if($Month=='03') echo " selected='selected'" ?> > มีนาคม</option>
<option value="04" <? if($Month=='04') echo " selected='selected'" ?> > เมษายน</option>
<option value="05" <? if($Month=='05') echo " selected='selected'" ?> > พฤษภาคม</option>
<option value="06" <? if($Month=='06') echo " selected='selected'" ?> > มิถุนายน</option>
<option value="07" <? if($Month=='07') echo " selected='selected'" ?> > กรกฎาคม</option>
<option value="08" <? if($Month=='08') echo " selected='selected'" ?> > สิงหาคม</option>
<option value="09" <? if($Month=='09') echo " selected='selected'" ?> > กันยายน</option>
<option value="10" <? if($Month=='10') echo " selected='selected'" ?> > ตุลาคม</option>
<option value="11" <? if($Month=='11') echo " selected='selected'" ?> > พฤศจิกายน</option>
<option value="12" <? if($Month=='12') echo " selected='selected'" ?> > ธันวาคม</option>
</select>
<select name="Year" id="Year">
<?php for($int_year = 0;$int_year < 10;$int_year++) { ?>
<option value="<?php echo date("Y") - $int_year ?>"><?php echo date("Y") - $int_year ?></option>
<?php } ?>
</select>
<select name="ctm_fix" id="ctm_fix">
<option value="">--ทั้งหมด--</option>
<?php
$strSQL = "SELECT * FROM service";
$objQuery = mysql_query($strSQL);
while($objResuut = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResuut["service_id"];?>">
<?=$objResuut["service_fix"];?>
</option>
<?php
}
?>
</select>
<input type="submit" name="Submit" value="ค้นหา" />
</p>
</form>
<?php
$arr_th_month = array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
$arr_service_data = array();
$str_service_condition = "";
if(strlen($_POST["ctm_fix"]) > 0)
{
$str_service_condition .= "where service_id = " . GetSQLValueString($_POST["ctm_fix"],"text") . "";
}
$sql = "SELECT * FROM service " . $str_service_condition;
//echo $sql;
$rs_service = mysql_query($sql);
while($row_service = mysql_fetch_array($rs_service))
{
$arr_data = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
$str_condition = "";
if(strlen($_POST["Year"]) > 0)
{
$str_condition .= "year(ctm_date) = '" . GetSQLValueString($_POST["Year"],"int") . "'";
}
else
{
$_POST["Year"] = date("Y");
$str_condition .= "year(ctm_date) = '" . date("Y") . "'";
}
if(strlen($_POST["Month"]) > 0)
{
$str_condition .= " and month(ctm_date) = '" . GetSQLValueString($_POST["Month"],"int") . "'";
}
else
{
$_POST["Month"] = date("m");
$str_condition .= " and month(ctm_date) = '" . date("m") . "'";
}
$str_condition .= ((strlen($str_condition) > 0)?" and ":"") . "ctm_fix = " . GetSQLValueString($row_service["service_id"],"text") . "";
$str_condition .= ((strlen($str_condition) > 0)?" and ":"") . "User_add = " . GetSQLValueString($_SESSION["UserID"],"text") . "";
$sql="SELECT * FROM data_customers " . ((strlen($str_condition) > 0)?"where ":"") . $str_condition;
//echo $sql;
$rs = mysql_query($sql);
while($row = mysql_fetch_array($rs))
{
$int_month = intval(date("d",strtotime($row['ctm_date'])));
$arr_data[$int_month - 1] = $arr_data[$int_month - 1]+1;
}
$arr_service['service_id'] = $row_service["service_id"];
$arr_service['service_fix'] = $row_service["service_fix"];
$arr_service['graph_data'] = $arr_data;
$arr_service_data[] = $arr_service;
}
//echo "<br/><br/>";
//print_r($arr_service_data);
?>
<?php $int_showday = date("t",strtotime($_POST['Year'] . "-" . $_POST['Month'] . "-" . "-1")); ?>
<center><table align="center"><tr><td>
<?php for($int_ser_index = 0;$int_ser_index < count($arr_service_data);$int_ser_index++) { ?>
<div style="float:left; margin:10px"><table border="1">
<?php for($int_index = 0;$int_index < $int_showday;$int_index++) { ?>
<tr>
<td><?php echo $int_index + 1; ?></td>
<td><?php echo $arr_service_data[$int_ser_index]['graph_data'][$int_index]; ?></td>
</tr>
<?php } ?>
</table></div>
<?php } ?>
<div style="clear:both"></div>
</td></tr></table></center>
<div id="datachart" style="height: 250px;"></div>
</p>
</center>
<link rel="stylesheet" href="vendors/morris/morris.css">
<script src="vendors/jquery-1.9.1.min.js"></script>
<script src="vendors/raphael-min.js"></script>
<script src="vendors/morris/morris.min.js"></script>
<script>
$(function() {
//Test Chart1
Morris.Bar({
element: 'datachart',
data: [
<?php for($int_index = 0;$int_index < $int_showday;$int_index++) { ?>
{ y: '<?php echo ($int_index + 1) ?>'<?php for($int_ser_index = 0;$int_ser_index < count($arr_service_data);$int_ser_index++) { ?>,s<?php echo $arr_service_data[$int_ser_index]['service_id'] ?>: <?php echo $arr_service_data[$int_ser_index]['graph_data'][$int_index] ?><?php } ?>}<?php echo(($int_index == $int_showday - 1))?"":"," ?>
<?php } ?>
],
xkey: 'y',
ykeys: [
<?php for($int_ser_index = 0;$int_ser_index < count($arr_service_data);$int_ser_index++) { ?>
<?php echo (($int_ser_index == 0))?"":"," ?>'s<?php echo $arr_service_data[$int_ser_index]['service_id'] ?>'
<?php } ?>
],
labels: [
<?php for($int_ser_index = 0;$int_ser_index < count($arr_service_data);$int_ser_index++) { ?>
<?php echo (($int_ser_index == 0))?"":"," ?>'<?php echo $arr_service_data[$int_ser_index]['service_fix'] ?>'
<?php } ?>
]
});
});
</script>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2013-12-23 20:13:06
|
|
|
|
|
Date :
2013-12-23 20:12:37 |
By :
aorplus |
View :
780 |
Reply :
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ง่ายมากไล่ tr td แนะนำให้เปิดกระดาษเปล่าขึ้นมาใหม่เพื่อทำความเข้าใจครับ
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<table width="100%" border="1">
<tr>
<td rowspan="2">CASE X</td>
<td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td>
<td>11</td><td>12</td><td>13</td><td>14</td><td>15</td><td>16</td><td>17</td><td>18</td><td>19</td><td>20</td>
<td>21</td><td>22</td><td>23</td><td>24</td><td>25</td><td>26</td><td>27</td><td>28</td>
<td>29</td><td>30</td><td>31</td>
</tr>
<tr>
<?
$i=1;
while ($i<=31) { //SQL ลงที่นี่โดยนำ $i ไปแทนค่าวันที่ และนำไปคิวรี่ในขั้นตอนต่อๆไป
?>
<td> <? echo "$i" ?></td>
<?
$i++;
}
?>
</tr>
</table>
|
|
|
|
|
Date :
2013-12-23 21:19:43 |
By :
meannerss |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณค่ะ
|
|
|
|
|
Date :
2013-12-23 21:42:13 |
By :
aorplus |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แหม. . ไม่ได้เข้ามานาน ระบบยังไม่เสร็จอีกเหรอครับ
|
|
|
|
|
Date :
2013-12-23 21:44:31 |
By :
meannerss |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อีกทางเลือกครับ
Code (PHP)
<?php
$days = 30;
$tb_header='<td>วันที่</td>';
$tb_data='<td>จำนวนครั้ง</td>';
$table='<table border="1"><tr><td rowspan="2" valign="middle">Case1</td>';
for($i=0;$i<$days;$i++){
$tb_header .='<td>'.($i+1).'</td>';
$tb_data .='<td></td>';
}
$table = $table.$tb_header.'</tr><tr>'.$tb_data.'</tr>';
echo $table;
?>
|
|
|
|
|
Date :
2013-12-23 22:14:29 |
By :
mangkunzo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|