|
 |
|
ช่วยสร้างตาราง เลขลำลับ ให้หน่อยครับ ขอร้องละครับ พอดีผมไม่รู้จะทำยังไงแล้วครับ ขอละเอียดหน่อยนะครับ |
|
 |
|
|
 |
 |
|
คือ ผมไม่รู้เลยว่า จะใช้คำสั่งอะไรดี
|
 |
 |
 |
 |
Date :
2014-10-08 23:10:48 |
By :
kenbongza1 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
if(!isset($start)) $start = 0;
$limit = '10'; // แสดงผลหน้าละกี่หัวข้อ
$strSearch =empty($_GET['txtsearch'])? "" :
" where s_name like '%{$_GET['txtsearch']}%' ".
"or s_lastname like '%{$_GET['txtsearch']}%' ".
"or s_code like '%{$_GET['txtsearch']}%' ".
"or s_tel like '%{$_GET['txtsearch']}%' ".
"or s_email like '%{$_GET['txtsearch']}%' ";
// เขียน คิวรี่ แยกบันทัดเพื่อการอ่านที่ทำให้เข้าใจได้ง่ายกว่าการเขียนบันทัดเดียว
//$sql = "select * from student $strSearch order by s_id desc "; // เปลือง bandwidth ช้า
$sql = "select count(s_id) from student $strSearch";
$result = mysql_query($sql );
//$num = mysql_num_rows($result);
list($num)=mysql_fetch_row($result);
$sql2 = "select * from student $strSearch order by s_id desc limit $start,$limit ";
$result2 = mysql_query($sql2 );
// $num2 = mysql_num_rows($result2); // ไม่ต้องใช้ for ให้ใช้ while
// for ( $i=1 ; $i<=$num2 ; $i++ ) {
// $row = mysql_fetch_array($result2); // อ้างอิงโดย keyfield ใช้ assoc
$i=0; // ถ้าอยากได้ เลขลำดับที่ใหม่ แต่ควรใช้ s_id แทน
while( $row = mysql_fetch_assoc($result2)){
//? > แบบนี้ถ้าเลี่ยงได้เลี่ยง ใช้ echo ต่อ String เอาดีกว่า
$i++; // จะใช้ $i หรือ $row[s_id] ก็เลือกเอานะครับ
echo '<tr>
<td align=center height=20 >',$row['s_id'],'</td>
<td align=center >',$row['s_code'],'</td>
<td>',$row['s_name'],' ',$row['s_lastname'],'</td>
<td align=center >
<a href="javascript:popup(\'s_detail.php?s_id=',$row['s_id'],'\',\'\',650,400)" >
<img src="viewIcon.png" width=20 height=20 border=0 /></a></td>
<td align=center ><a href="editstudent.php?s_id=',$row['s_id'],'" >
<img src="Text Edit Icon.jpg" width=20 height=20 border=0 /></a></td>
<td align=center ><a href="javascript: confirmDelete(\'delstudent.php?s_id=',$row['s_id'],'\')" >
<img src="edit-delete-icon.png" width=20 height=20 border=0 /></a></td>
</tr>';
}
?>
ปล. คำสั่ง where จัดเรียงลำดับการค้นหา จาก ความยาว น้อย ไปหาความยาวมาก จะหาได้เร็วขึ้นนะครับ
และถ้ารู้ปริมาณการค้นหายิ่งช่วยได้มาก
|
ประวัติการแก้ไข 2014-10-09 04:51:22
 |
 |
 |
 |
Date :
2014-10-09 04:38:57 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ คุณ Chaidhanan
|
 |
 |
 |
 |
Date :
2014-10-09 13:42:10 |
By :
kenbongza1 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|