|
 |
|
ผมกำลังทำการออกรายงานอยู่ครับ แต่พอดีกำลังติดที่ต้องดึงข้อมูลมาจาก 2 ตาราง ครับผม |
|
 |
|
|
 |
 |
|
ถ้าคิดว่าไม่มีความรู้เรื่อง join แนะนำให้ใช้วิธีง่ายๆ แบบนี้ครับ ถ้า join ลองไปดู โค้ดล่างสุดละกัน
Code (PHP)
<?
$sql1 = "SELECT * FROM users WHERE year LIKE '%$typeList%' AND status = 'F'"; ตรงนี้ครับคือต้องใส่ออกทั้ง 2 ตารางนี้
$dbquery1 = mysql_db_query($dbname, $sql1) or die("Can't Query");
?>
<table width="100%" border="1" align="center" bordercolor="#000" cellspacing="0">
<tr>
<th width="20%" bgcolor="#FFFFCC">เลขประจำตัวนักเรียน</th>
<th width="20%" bgcolor="#FFFFCC">ชื่อ</th>
<th width="20%" bgcolor="#FFFFCC">นามสกุล</th>
<th width="20%" bgcolor="#FFFFCC">ที่อยู๋</th>
<th width="20%" bgcolor="#FFFFCC">เบอร์โทร</th>
<th width="20%" bgcolor="#FFFFCC">ปีการศึกษา</th>
<th width="20%" bgcolor="#FFFFCC">GPA</th>
<th width="20%" bgcolor="#FFFFCC">ประวัติ</th>
</tr>
<?php
$c = 0;
while($result1 = mysql_fetch_array($dbquery1))
{
####
$sql2 = "SELECT * FROM student where user_id = '$result1[user_id]'";
$dbquery2 = mysql_db_query($dbname, $sql2) or die("Can't Query");
$result2=mysql_fetch_array($dbquery2 );
#ใช้ ตัว $result2 ในการเรียกค่าของ student ออกมา
####
$c++;
if($c%2==0)
{
$bg = "#FFFFCC";
}
else
{
$bg = "#ADD8E6";
}
?>
<tr bgcolor="<?=$bg;?>">
<td><?=$result1["user_id"];?></td>
<td><?=$result1["firstname"];?></td>
<td><?=$result1["lastname"];?></td>
<td><?=$result1["address"];?></td>
<td><?=$result1["telephone"];?></td>
<td><?=$result1["year"];?></td>
<td><?=$result1["gpa"];?></td>
<td><?=$result1["behavior"];?></td>
<td><?=$result2["ชื่อฟิลค์ในตาราง student"];?></td>
</tr>
<?
}
mysql_close();
?>
Code (PHP)
SELECT *
FROM users
INNER JOIN student
ON student.user_id = users.user_id
WHERE year LIKE '%$typeList%' AND status = 'F'
|
 |
 |
 |
 |
Date :
2013-01-29 22:13:06 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าผมอยากจะทำให้ ที่แสดงออกมาจากฐานข้อมูลสามารถกดไปที่หน้าอื่นได้ต้องทำยังไงครับ ใช้ตัวนี้ครับผม <td><?=$result1["user_id"];?></td> เหมือนแบบนี้อะครับ <td align="center"><a href="student_edit.php?user_id=<?=$result1["user_id"];?>"'>แก้ไข</a></td>
|
 |
 |
 |
 |
Date :
2013-01-29 22:51:12 |
By :
tangsupap |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|