|
 |
|
ถ้าต้องการทำตารางในหน้ารายงานให้มันโชว์เป็นหัวตาราง ต้องเขียนโค๊ดไงคะ |
|
 |
|
|
 |
 |
|
เอาโค้ดมาแปะไว้ครับ เด่วจะมีคนมาแก้ให้ได้ไวกว่า มานั่งเดาว่าเกิดอะไร
|
 |
 |
 |
 |
Date :
2011-02-11 12:17:32 |
By :
ๅ/- |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต้องเขียนแยกเป็น 2 ส่วนครับ
ส่วนแรก ก็เป็นส่วนของหัวข้อที่ต้องการโชว์ ให้เขียนแสดงออกมาได้เลย
ส่วนที่สอง เป็นส่วนที่ดึงข้อมูลออกมาโชว์ โดยในส่วนนี้ให้ทำการวนลูป ดึงข้อมูลออกมาโชว์ให้ครบ
เข้าใจว่าที่มันซ้ำออกมาหมดทุกข้อมูล น่าจะเกิดจากการวนลูปหัวข้อเข้าไปด้วย 
|
 |
 |
 |
 |
Date :
2011-02-11 12:25:27 |
By :
taleblue |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เขียนในส่วนหัวตารางอยู่นอกลูป ตามนี้
Code (PHP)
<table>
<tr>
<td>วันที่</td>
<td>รหัส</td>
<td>ชื่อ</td>
<td>นามสกุล</td>
</tr>
<?
$query=mssql_query("???????");
while($row=mysql_fetch_array($query)){?>
<tr>
<td>ตัวแปรที่ต้องการแสดง</td>
<td>ตัวแปรที่ต้องการแสดง</td>
<td>ตัวแปรที่ต้องการแสดง</td>
<td>ตัวแปรที่ต้องการแสดง</td>
</tr>
<?}?>
</table>
|
 |
 |
 |
 |
Date :
2011-02-11 13:08:43 |
By :
NPPEP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จัดไปครับ เอาไปปรับใช้เองนะ
Code (PHP)
$host = "localhost";
$database = "dbname";
$username = "root";
$password = "1234";
$connect = mysql_connect($host, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database, $connect);
mysql_query("set NAMES tis620");
$sql="SELECT id,name,surname,tel FROM member";
$result = mysql_query($sql , $connect);
echo"
<table whidth= \"100% \">
<tr>
<td><B>ID</B></td>
<td><B>NAME</B></td>
<td><B>SURNAME</B></td>
<td><B>TEL</B></td>
<tr>";
while ($data = mysql_fetch_array($result)) {
echo "
<tr>
<td>$data['id']</td>
<td>$data['name']</td>
<td>$data['surname']</td>
<td>$data['tel']</td>
<tr>";
}//end while
echo"</table>";
|
 |
 |
 |
 |
Date :
2011-02-11 13:12:07 |
By :
avsqlz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค๊ดประมาณนี้อ่ะค่ะ
if($id_val != null){
$link = mysql_connect("localhost", "root", "1234");
$sql = "use taxi";
$result = mysql_query($sql);
$sql = "select add_newmember.id, add_newmember.name, add_newmember.lastname, add_tourit.date,add_tourit.adult,add_tourit.children,add_tourit.total From add_newmember,add_tourit where add_newmember.id ='$id_val' and add_newmember.id=add_tourit.id order by add_tourit.date ASC;";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if($num_rows == "")
{
echo "ไม่พบข้อมูลที่ค้นหา"."<p>";
echo "<a href=showtaxi.php>กลับหน้าแสดงข้อมูล</a></br>";
}
else {
while ($dbarr = mysql_fetch_array($result))
{
echo " วันที่ :".$dbarr[date]. " รหัส :".$dbarr[id]. " ชื่อ :".$dbarr[name]. " นามสกุล :".$dbarr[lastname]. " จำนวนผู้ใหญ่ :".$dbarr[adult]. " คน". " จำนวนเด็ก :".$dbarr[children]. " คน". " จำนวนทั้งหมด :".$dbarr[total]. " คน"."<p>";
}
|
 |
 |
 |
 |
Date :
2011-02-11 13:15:21 |
By :
fuang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยดูให้หน่อยคร๊า
|
 |
 |
 |
 |
Date :
2011-02-11 13:50:46 |
By :
fuang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำได้ละค่ะ แต่ผลปรากฏออกมา เป็นแบบนี้ค่ะ
|
 |
 |
 |
 |
Date :
2011-02-11 14:51:44 |
By :
fuang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
[
โค๊ด แบบนี้อ่ะค่ะ
$link = mysql_connect("localhost", "root", "1234");
$sql = "use taxi";
$result = mysql_query($sql);
$sql = "select add_newmember.id, add_newmember.name, add_newmember.lastname, add_tourit.date,add_tourit.adult,add_tourit.children,add_tourit.total From add_newmember,add_tourit where add_newmember.id ='$id_val' and add_newmember.id=add_tourit.id order by add_tourit.date ASC;";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if($num_rows == "")
{
echo "ไม่พบข้อมูลที่ค้นหา"."<p>";
echo "<a href=showtaxi.php>กลับหน้าแสดงข้อมูล</a></br>";
}
else {
echo "<table border = 1 BORDERCOLOR= #F90 width= 1000 height= 20 >
<tr>
<center><td><B>วันที่</B></td>
<td><B>รหัส</B></td>
<td><B>ชื่อ</B></td>
<td><B>นามสกุล</B></td>
<td><B>จำนวนผู้ใหญ่</B></td>
<td><B>จำนวนเด็ก</B></td>
<td><B>จำนวนทั้งหมด</B></td>
</center>
</tr>";
while ($dbarr = mysql_fetch_array($result))
{
echo "
<tr>
<td>$dbarr[date]</td>
<td>$dbarr[id]</td>
<td>$dbarr[name]</td>
<td>$dbarr[lastname]</td>
<td>$dbarr[adult]</td>
<td>$dbarr[children]</td>
<td>$dbarr[total]</td>
</tr>
</table>";}
ไม่เข้าใจว่าไมมันมาแค่ข้อมูลเดียว หุหุ งง ช่วยหน่อยนะคะ
|
 |
 |
 |
 |
Date :
2011-02-11 14:54:31 |
By :
fuang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$link = mysql_connect("localhost", "root", "1234");
$sql = "use taxi";
$result = mysql_query($sql);
$sql = "select add_newmember.id, add_newmember.name, add_newmember.lastname, add_tourit.date,add_tourit.adult,add_tourit.children,add_tourit.total From add_newmember,add_tourit where add_newmember.id ='$id_val' and add_newmember.id=add_tourit.id order by add_tourit.date ASC;";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if($num_rows == "")
{
echo "ไม่พบข้อมูลที่ค้นหา"."<p>";
echo "<a href=showtaxi.php>กลับหน้าแสดงข้อมูล</a></br>";
}
else {
echo "<table border = 1 BORDERCOLOR= #F90 width= 1000 height= 20 >
<tr>
<center><td><B>วันที่</B></td>
<td><B>รหัส</B></td>
<td><B>ชื่อ</B></td>
<td><B>นามสกุล</B></td>
<td><B>จำนวนผู้ใหญ่</B></td>
<td><B>จำนวนเด็ก</B></td>
<td><B>จำนวนทั้งหมด</B></td>
</center>
</tr>";
while ($dbarr = mysql_fetch_array($result))
{
echo "
<tr>
<td>$dbarr[date]</td>
<td>$dbarr[id]</td>
<td>$dbarr[name]</td>
<td>$dbarr[lastname]</td>
<td>$dbarr[adult]</td>
<td>$dbarr[children]</td>
<td>$dbarr[total]</td>
</tr>
}//ปิดวงเล็บเงื่อนไขนี้ด้วยค่ะ while ($dbarr = mysql_fetch_array($result)){
</table>";
}//วงเล็บปิดตรงนี้คือปิดที่เงื่อนไขนี้หรือเปล่า if($num_rows == "")
|
 |
 |
 |
 |
Date :
2011-02-11 15:07:45 |
By :
NPPEP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งะ มันยังเออเร่ออยู่อ่ะค่ะ เอาโค๊ดแบบเต็มๆไปดูให้หน่อยนะคะ รบกวนอีกรอบค่ะ
$link = mysql_connect("localhost", "root", "1234");
$sql = "use taxi";
$result = mysql_query($sql);
$sql = "select add_newmember.id, add_newmember.name, add_newmember.lastname, add_tourit.date,add_tourit.adult,add_tourit.children,add_tourit.total From add_newmember,add_tourit where add_newmember.id ='$id_val' and add_newmember.id=add_tourit.id order by add_tourit.date ASC;";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if($num_rows == "")
{
echo "ไม่พบข้อมูลที่ค้นหา"."<p>";
echo "<a href=showtaxi.php>กลับหน้าแสดงข้อมูล</a></br>";
}
else {
echo "<table border = 1 BORDERCOLOR= #F90 width= 1000 height= 20 >
<tr>
<center><td><B>วันที่</B></td>
<td><B>รหัส</B></td>
<td><B>ชื่อ</B></td>
<td><B>นามสกุล</B></td>
<td><B>จำนวนผู้ใหญ่</B></td>
<td><B>จำนวนเด็ก</B></td>
<td><B>จำนวนทั้งหมด</B></td>
</center>
</tr>";
while ($dbarr = mysql_fetch_array($result))
{
echo "
<tr>
<td>$dbarr[date]</td>
<td>$dbarr[id]</td>
<td>$dbarr[name]</td>
<td>$dbarr[lastname]</td>
<td>$dbarr[adult]</td>
<td>$dbarr[children]</td>
<td>$dbarr[total]</td>
</tr>
</table>";}
//echo " วันที่ :".$dbarr[date]. " รหัส :".$dbarr[id]. " ชื่อ :".$dbarr[name]. " นามสกุล :".$dbarr[lastname]. " จำนวนผู้ใหญ่ :".$dbarr[adult]. " คน". " จำนวนเด็ก :".$dbarr[children]. " คน". " จำนวนทั้งหมด :".$dbarr[total]. " คน"."<p>";
$result = mysql_query($sql);
$sql = "SELECT SUM(adult) AS adult, SUM(children) AS children,SUM(total) AS total FROM add_tourit where id = '$id_val';";
$result = mysql_query($sql);
$dbarr = mysql_fetch_array($result);
echo "ผลรวมต่างชาติผู้ใหญ่ :".$dbarr[adult]." คน" ."<p>";
echo "ผลรวมต่างชาติเด็ก :".$dbarr[children]." คน" ."<p>";
echo "จำนวนทั้งหมด :".$dbarr[total]." คน"."<p>";
//echo "<a href=showtaxi.php>กลับหน้าแสดงข้อมูล</a></br>";
mysql_close($link);
echo "<style type=text/css>
@media print{
#no_print{display:none;}
}
</style>
<div id=no_print>
<a href=showtaxi.php>กลับหน้าแสดงข้อมูล</a><p>
<input type=button value=print onclick=window.print()>
</div>";}}
รบกวนอีกรอบน๊า....
|
 |
 |
 |
 |
Date :
2011-02-11 15:29:08 |
By :
fuang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ละค่ะ ขอบคุณมากๆๆๆๆ
|
 |
 |
 |
 |
Date :
2011-02-11 15:30:36 |
By :
fuang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คำสั่ง sql เชื่อมตารางใช้ left outer join ดีกว่าครับ
|
 |
 |
 |
 |
Date :
2011-02-11 15:32:55 |
By :
avsqlz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|