|
|
|
ขอสอบถามการใช้ mssql กับการดึงข้อมูลมาจาก microsoft 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" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
<?
include "dbconnect.php";
include "menu.php";
$date_s = $_REQUEST['date_s'];
$date_e = $_REQUEST['date_e'];
$day_s = substr($date_s,0,2);
$month_s = substr($date_s,2,2);
$year_s = substr($date_s,4,4);
//$date_start = $year_s."-".$month_s."-".$day_s."<br>";
if ($month_s == 01)
{
$month_s = "Jan";
}
else if ($month_s == 02)
{
$month_s = "Feb";
}
else if ($month_s == 03)
{
$month_s = "Mar";
}
else if ($month_s == 04)
{
$month_s = "Apr";
}
else if ($month_s == 05)
{
$month_s = "May";
}
else if ($month_s == 06)
{
$month_s = "Jun";
}
else if ($month_s == 07)
{
$month_s = "Jul";
}
else if ($month_s == 08)
{
$month_s = "Aug";
}
else if ($month_s == 09)
{
$month_s = "Sep";
}
else if ($month_s == 10)
{
$month_s = "Oct";
}
else if ($month_s == 11)
{
$month_s = "Nov";
}
else if ($month_s == 12)
{
$month_s = "Dec";
}
//echo $date_start = $year_s."-".$month_s."-".$day_s;
echo $date_start = $month_s." ".$day_s." ".$year_s;
$day_e = substr($date_e,0,2);
$month_e = substr($date_e,2,2);
$year_e = substr($date_e,4,4);
//$date_end = $year_e."-".$month_e."-".$day_e;
if ($month_e == 01)
{
$month_e = "Jan";
}
else if ($month_e == 02)
{
$month_e = "Feb";
}
else if ($month_e == 03)
{
$month_e = "Mar";
}
else if ($month_e == 04)
{
$month_e = "Apr";
}
else if ($month_e == 05)
{
$month_s = "May";
}
else if ($month_s == 06)
{
$month_e = "Jun";
}
else if ($month_e == 07)
{
$month_e = "Jul";
}
else if ($month_e == 08)
{
$month_e = "Aug";
}
else if ($month_e == 09)
{
$month_e = "Sep";
}
else if ($month_e == 10)
{
$month_e = "Oct";
}
else if ($month_e == 11)
{
$month_e = "Nov";
}
else if ($month_e == 12)
{
$month_e = "Dec";
}
echo $date_end = $month_e." ".$day_e." ".$year_e;
?>
<br>
<style>
.verdana15
{
font-family:verdana;
font-size:15px;
}
</style>
<table width="80%" border="1" align="center" class="verdana15">
<tr>
<td width="9%" align = "center">SO</td>
<td width="10%" align = "center">Job Create</td>
<td width="8%" align = "center">Customer Name</td>
<td width="8%" align = "center">No.</td>
<td width="3%" align = "center">Service</td>
<td width="10%" align = "center">SO_Type</td>
<td width="10%" align = "center">Item Number</td>
<td width="" align = "center">Description 1</td>
<td width="" align = "center">Description</td>
</tr>
<?
$nameSQL = "SELECT * FROM nc_workinglist WHERE Date(Created Date) BETWEEN '$date_start' AND '$date_end' ORDER BY Create_Date DESC";
$query = mssql_query($nameSQL);
while($rs = mssql_fetch_array($query))
{
$DB0 = $rs[0];
$DB36 = $rs[36];
$DB2 = $rs[2];
$DB7 = $rs[7];
$DB12 = $rs[12];
$DB8 = $rs[8];
$DB9 = $rs[9];
$DB10 = $rs[10];
$DB11 = $rs[11];
?>
<tr class="verdana15">
<td><center><? echo $DB0 ;?></center></td>
<td><center><? echo $DB36; ?></center></td>
<td><center><? echo $DB2; ?></center></td>
<td><center><? echo $DB7; ?></center></td>
<td><center><? echo $DB12; ?></center></td>
<td><center><? echo $DB8; ?></center></td>
<td><center><? echo $DB9; ?></center></td>
<td><center><? echo $DB10; ?></center></td>
<td><center><? echo $DB11; ?></center></td>
</tr>
<?php
}
?>
</table>
<?
//$nameSQL = "SELECT * FROM nc_workinglist WHERE Date(Create_Date) BETWEEN '$date_start' AND '$date_end' ORDER BY Create_Date DESC";
?>
จาก code พอรันแล้วขึ้นดังรูปครับ ไม่ทราบว่าต้องแก้ไขตรงไหนครับ
Tag : PHP, MySQL, HTML/CSS, JavaScript, CakePHP
|
|
|
|
|
|
Date :
2013-05-20 16:13:15 |
By :
Anonymous |
View :
911 |
Reply :
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$nameSQL = "SELECT * FROM nc_workinglist WHERE CONVERT(CreatedDate,101) BETWEEN '$date_start' AND '$date_end' ORDER BY Create_Date DESC";
|
|
|
|
|
Date :
2013-05-20 23:12:21 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
<?
include "dbconnect_nav.php";
include "menu.php";
$date_s = $_REQUEST['date_s'];
$date_e = $_REQUEST['date_e'];
$day_s = substr($date_s,0,2);
$month_s = substr($date_s,2,2);
$year_s = substr($date_s,4,4);
$date_start = $year_s."-".$month_s."-".$day_s."<br>";
if ($month_s == 01)
{
$month_s = "Jan";
}
else if ($month_s == 02)
{
$month_s = "Feb";
}
else if ($month_s == 03)
{
$month_s = "Mar";
}
else if ($month_s == 04)
{
$month_s = "Apr";
}
else if ($month_s == 05)
{
$month_s = "May";
}
else if ($month_s == 06)
{
$month_s = "Jun";
}
else if ($month_s == 07)
{
$month_s = "Jul";
}
else if ($month_s == 08)
{
$month_s = "Aug";
}
else if ($month_s == 09)
{
$month_s = "Sep";
}
else if ($month_s == 10)
{
$month_s = "Oct";
}
else if ($month_s == 11)
{
$month_s = "Nov";
}
else if ($month_s == 12)
{
$month_s = "Dec";
}
//echo $date_start = $year_s."-".$month_s."-".$day_s;
echo $date_start = $month_s." ".$day_s." ".$year_s;
$day_e = substr($date_e,0,2);
$month_e = substr($date_e,2,2);
$year_e = substr($date_e,4,4);
$date_end = $year_e."-".$month_e."-".$day_e;
if ($month_e == 01)
{
$month_e = "Jan";
}
else if ($month_e == 02)
{
$month_e = "Feb";
}
else if ($month_e == 03)
{
$month_e = "Mar";
}
else if ($month_e == 04)
{
$month_e = "Apr";
}
else if ($month_e == 05)
{
$month_s = "May";
}
else if ($month_s == 06)
{
$month_e = "Jun";
}
else if ($month_e == 07)
{
$month_e = "Jul";
}
else if ($month_e == 08)
{
$month_e = "Aug";
}
else if ($month_e == 09)
{
$month_e = "Sep";
}
else if ($month_e == 10)
{
$month_e = "Oct";
}
else if ($month_e == 11)
{
$month_e = "Nov";
}
else if ($month_e == 12)
{
$month_e = "Dec";
}
echo $date_end = $month_e." ".$day_e." ".$year_e;
?>
<br>
<style>
.verdana15
{
font-family:verdana;
font-size:15px;
}
</style>
<table width="80%" border="1" align="center" class="verdana15">
<tr>
<td width="9%" align = "center">SO</td>
<td width="10%" align = "center">Job Create</td>
<td width="8%" align = "center">Customer Name</td>
<td width="8%" align = "center">No.</td>
<td width="3%" align = "center">Service</td>
<td width="10%" align = "center">SO_Type</td>
<td width="10%" align = "center">Item Number</td>
<td width="" align = "center">Description 1</td>
<td width="" align = "center">Description</td>
</tr>
<?
//$nameSQL = "SELECT * FROM joblist WHERE CONVERT('Created Date' , '19') BETWEEN '$date_start' AND '$date_end'";
//$nameSQL = "SELECT DATE(Created Date) FROM joblist BETWEEN '2012-02-18 00:00:00.000' AND '2012-02-18 00:00:00.000'";
//$nameSQL = "SELECT DATE(Created Date) AS DaySel FROM joblist";
//$nameSQL = "SELECT * FROM joblist WHERE Created Date BETWEEN 'Dec 30 2012 12:00AM' AND 'Dec 30 2012 12:00AM'";
//$nameSQL = "SELECT CAST('Created Date' AS DATE) FROM joblist";
//CAST(datetime_fields AS DATE)
//$nameSQL = "SELECT * FROM joblist WHERE CONVERT('Created Date',101) BETWEEN '2012-02-18 00:00:00.000' AND '2012-02-18 00:00:00.000'";
//$nameSQL = "SELECT DAY('Created Date') AS DaySel FROM joblist";
$nameSQL = "SELECT * FROM joblist WHERE CONVERT(Created Date,101) BETWEEN '$date_start' AND '$date_end'";
$query = mssql_query($nameSQL);
while($rs = mssql_fetch_array($query))
{
$DB0 = $rs[0];
$DB36 = $rs[36];
$DB2 = $rs[2];
$DB7 = $rs[7];
$DB12 = $rs[12];
$DB8 = $rs[8];
$DB9 = $rs[9];
$DB10 = $rs[10];
$DB11 = $rs[11];
?>
<tr class="verdana15">
<td><center><? echo $DB0 ;?></center></td>
<td><center><? echo $DB36; ?></center></td>
<td><center><? echo $DB2; ?></center></td>
<td><center><? echo $DB7; ?></center></td>
<td><center><? echo $DB12; ?></center></td>
<td><center><? echo $DB8; ?></center></td>
<td><center><? echo $DB9; ?></center></td>
<td><center><? echo $DB10; ?></center></td>
<td><center><? echo $DB11; ?></center></td>
</tr>
<?php
}
?>
</table>
ผมลองแก้โคดตามนี้นะครับ เพราะว่า ข้อมูลต้องไปดึงมาจาก table ชื่อ joblist และฟิล์ใน table joblist ที่เราจะค้นหาชื่อ Created Date
แต่ว่ามันยังไม่ได้ครับ มัน error ตานี้ครับ
|
|
|
|
|
Date :
2013-05-23 11:27:11 |
By :
Anonymous |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณบอกว่า Table คุณชื่อ joblist ฟิลด์ชื่อ Created_Date
ก็น่าจะ Select แบบนี้เปล่า ลองดูๆๆๆ
$nameSQL = "SELECT * FROM joblist WHERE Created_Date BETWEEN '$date_start' AND '$date_end' ORDER BY Create_Date DESC";
$query = mssql_query($nameSQL);
แต่ $date_start กับ $date_end จะต้องมีค่าตรงกับในฐานข้อมูลนะครับ ^__^
|
|
|
|
|
Date :
2013-05-23 14:31:11 |
By :
tumkung_narakjung |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|