|
 |
|
ต้องการใช้ a href ในตารางที่ดึงมาจาก database (ดึงมาจากหลายตาราง) |
|
 |
|
|
 |
 |
|

คือต้องการใส่ a href ในช่องสถานะ ที่ขึ้นว่าค้างชำระทุกอันในตารางอ่ะคะ ให้มันขึ้นว่า ชำระงิน แต่ข้อมุลในตาราง มันดึงมาจากตารางหลายตารางในฐานข้อมูลอ่ะค่ะ แล้วเอามาเปรียบเทียบกัน ถึงจะออกมาเป็นตารางอันนั้นที่หน้าเว็บไซต์
โค้ด
Code (PHP)
<?php
session_start();
if (isset($_SESSION['login'])) { // อย่าลืม ต้องประการทุกครั้ง
echo "<center><p><p><b>ยินดีต้อนรับ... <font color='blue'>".$_SESSION['login']."</font></b></center>";
}else{
echo "<script type='text/javascript'>";
echo "windoe.location = 'error.php'";
echo "</script>";
}
include("connect01.inc");
$day_t0 = date("d-m-Y");
list($d, $m, $Y) = explode("-", $day_t0);
$Y = $Y+543;
$com_value = array("$d", "$m", "$Y");
$day_t1 = implode("-", $com_value);
$db = "asteriskproj";
$result = mysql_select_db($db);
mysql_query("SET NAMES UTF8");
if(!$result){
die('Could not find database called asteriskproj: '. mysql_error());
}
$sql = "SELECT member.name, stadium.stadium, time_fix.ti_fix, status.status FROM (member, stadium, time_fix, status) WHERE (member.id_card = stadium.namer and time_fix.num_fix = stadium.time and need_date = '$day_t1' and stadium.cash = status.num_st)";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
$num_fields = mysql_num_fields($result);
echo "<center>";
echo "<table bgcolor=00ff7f width=750px border=1px><tr><th>ชื่อผู้จอง</th><th>สนามที่</th><th>เวลาที่จอง</th><th>สถานะ</th></tr>";
$col = mysql_query($result);
while($row = mysql_fetch_row($col))
{
echo "<th>$row[0]</th>";
}
echo "</tr>";
$i = 0;
while($i<$num_rows){
$data = mysql_fetch_array($result);
echo "<tr align=\"center\">";
for($j=0; $j<$num_fields; $j++){
echo "<td>$data[$j]</td>";
}
echo "</tr>";
$i++;
}
echo "</table></center>";
mysql_close($link);
?>
เราสามารถจะใส่ได้ไหมคะ
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2014-05-23 15:54:39 |
By :
iiichoompuiii |
View :
1279 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วในตารางที่ดึงมาเนี่ย มีฟิลด์ไหนที่บอกหรือเปล่าว่าชำระแล้ว ที่ทำไว้เป็นยังไงครับ ได้ทำหรือไม่ได้ทำช่องนี้หรือเปล่า ถ้าได้ทำ และดึงข้อมูลมาแล้ว ก็ใช้ while ลูปดึงมาแบบปรกติ แต่มาเปรียบเทียบแบบนี้นะครับ แต่ถ้ายังไม่ได้ทำไว้ ก็กลับไปทำมาก่อนครับ
if($pay==1){
$pays='<a href="updatepay.php">ยังไม่ได้จ่าย</a>";
}else{
$pays="จ่ายแล้ว";
}
คร่าวๆประมาณนี้ครับ
|
 |
 |
 |
 |
Date :
2014-05-23 16:11:59 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือในฟิลสถานะนะนั่นละคะ มันเก็บค่า 0 ไว้ ซึ่งไปเปรียบเทียบกับอีกตารางในฐานข้อมูลแล้วค่ามันออกมาว่าค้างชำระ ซึ่งในฟิลสถานะที่มันขึ้นว่าค้างชำระ จะให้ใส่แทก a href ว่า ชำระเงินไปแทนอะคะ ถ้าใส่ if เราจะใส่ไปตรงไหนอะคะ
|
 |
 |
 |
 |
Date :
2014-05-23 16:54:45 |
By :
iiichoompuiii |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$i = 0;
while($i<$num_rows){
$data = mysql_fetch_array($result);
echo "<tr align=\"center\">";
for($j=0; $j<$num_fields; $j++){
echo "<td>$data[$j]</td>";
}
คำสั่งชุดนี้มันจะทำการวน num_rows ออกมา ดูตรง $data[$j] ครับ ต้องเอามาใส่ในนี้ และต้องดูว่ามันตรงกับ $data[3] ซึ่งเป็นข้อมูลแถวสุดท้ายด้วยหรือเปล่า
|
 |
 |
 |
 |
Date :
2014-05-23 17:21:57 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|