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,027

HOME > PHP > PHP Forum > ขอสอบถามการใช้ mssql กับการดึงข้อมูลมาจาก microsoft sql หน่อยครับ



 

ขอสอบถามการใช้ mssql กับการดึงข้อมูลมาจาก microsoft sql หน่อยครับ

 



Topic : 095455

Guest




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 พอรันแล้วขึ้นดังรูปครับ ไม่ทราบว่าต้องแก้ไขตรงไหนครับ

date



Tag : PHP, MySQL, HTML/CSS, JavaScript, CakePHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-05-20 16:13:15 By : Anonymous View : 868 Reply : 7
 

 

No. 1



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

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

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

Quote:
include "dbconnect.php";


น่าจะ Error ตั้งแต่การ Connect ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-20 16:19:10 By : mr.win
 


 

No. 2

Guest


ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2013-05-20 16:19:10
รายละเอียดของการตอบ ::
แก้แล้วครับ มันขึ้นแบบนี้ครับ

date1


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-20 16:21:55 By : Anonymous
 

 

No. 3



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

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

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

Quote:
$nameSQL = "SELECT * FROM nc_workinglist WHERE Date(Created Date) BETWEEN '$date_start' AND '$date_end' ORDER BY Create_Date DESC";


SQL Server น่าจะไม่มี Date ครับ ลองดูพวก CONVERT ของ SQL Server ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-20 17:26:06 By : mr.win
 


 

No. 4

Guest


ตอบความคิดเห็นที่ : 3 เขียนโดย : mr.win เมื่อวันที่ 2013-05-20 17:26:06
รายละเอียดของการตอบ ::
แล้วผมจะค้นหาข้อมูลในฟิล์ชื่อ Created Date โดยใช้ BETWEN ยังไงครับ คือในฟิล์ดังกล่าว เขาเก็บข้อมูลไว้ดังนี้ครับ

Dec 30 2012 12:00AM

ผมจะค้นหายังไงโดยไม่ต้องไปสนใจเวลาอ่ะครับใน mssql พอดีไม่เคยใช้ครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-20 17:47:21 By : Anonymous
 


 

No. 5



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

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

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

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
 


 

No. 6

Guest


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 ตานี้ครับ

thaicreate
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-23 11:27:11 By : Anonymous
 


 

No. 7



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



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


คุณบอกว่า 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
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอสอบถามการใช้ mssql กับการดึงข้อมูลมาจาก microsoft sql หน่อยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 00
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 อัตราราคา คลิกที่นี่