หมดปัญญาแล้วครับ ทำยังไงให้มัน join กันได้ครับ TT"
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=utf-8" />
<?
include("../../library/class.mysqldb.php");
include("../../library/config.inc.php");
## เพิ่มลงฐานข้อมูล
if(isset($_REQUEST["submit"])) {
for($j=1;$j<=20;$j++) {
for($i=0;$i<=count($_REQUEST["time_start".$j.""]);$i++) {
if($_POST["time_start".$j.""][$i] != "") {
$sql="INSERT INTO package_detail (
`pack_name` ,
`day` ,
`time_start` ,
`time_end` ,
`amper_att` ,
`attraction` ,
`m_id`
)
VALUES (
'".$_GET["pack_name"]."',
'วันที่ ".$j."',
'".$_POST["time_start".$j.""][$i]."',
'".$_POST["time_end".$j.""][$i]."',
'".$_POST["amper_att".$j.""][$i]."',
'".$_POST["attraction".$j.""][$i]."',
'".$_SESSION["m_id"]."'
)";
mysql_query($sql);
}
}
}
print "<meta http-equiv=refresh content=0;URL=tour_list.php>";
}
$sql="select * from package_type where packagetype_id='".$_GET["ptype"]."'";
#echo $sql;
$result = mysql_query($sql);
$rs=mysql_fetch_object($result);
$days=$rs->p_day;
?>
<title>Untitled Document</title>
<style type="text/css">
<!--
.style3 {font-family: "Cordia New"; font-size: 20px; }
.style5 {font-family: "Cordia New"; font-size: 20px; font-weight: bold; }
.style9 {color: #FFFFFF}
.style10 {font-family: "Cordia New"; font-size: 20px; color: #FFFFFF; }
-->
</style>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<? for($d=1;$d<=$days;$d++) { ?>
<label></label>
<table width="740" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="992" colspan="2" style="border:dotted; border-width:2px; border-color:#009900"><table width="962" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#E0E0E0">
<tr>
<td width="962" align="center" bgcolor="#009900"><span class="style5 style9">แพ๊คเก็จ :: <?=$_REQUEST['pack_name']?> ใน วันที่ <?=$d?></span></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><span class="style5">กิจกรรมช่วงเช้า</span></td>
</tr>
<tr>
<td><table width="961" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="178" align="left" bgcolor="#009900" class="style3 style9">ช่วงเวลา</td>
<td width="189" align="left" bgcolor="#009900"><span class="style10">อยู่ที่อำเภอ</span></td>
<td width="316" align="left" bgcolor="#009900"><span class="style10">สถานที่ท่องเที่ยว</span></td>
<td width="260" bgcolor="#009900" class="style10">กิจกรรมเพิ่มเติม</td>
</tr>
<tr>
<td valign="top" bgcolor="#E0E0E0"><span class="style3">เวลา
<input name="time_start<?=$d?>[]" type="text" id="time_start<?=$d?>[]" size="5" />
-
<input name="time_end<?=$d?>[]" type="text" id="time_end<?=$d?>[]" size="5" />
</span></td>
<td align="left" valign="top" bgcolor="#E0E0E0"><span class="style3">
<label>
<select name="amper_att<?=$d?>[]" id="amper_att<?=$d?>[]">
<?
$sql="select * from amper";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->amper_name?>"><?=$rs->amper_name?></option>
<? } ?>
</select>
</label>
</span></td>
<td align="left" valign="top" bgcolor="#E0E0E0"><label>
<select name="attraction<?=$d?>[]" id="attraction<?=$d?>[]">
<?
$sql="select * from attraction";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->attraction?>"><?=$rs->attraction?></option>
<? } ?>
</select>
</label></td>
<td align="left" bgcolor="#E0E0E0"><textarea name="note<?=$d?>[]" id="textarea7" cols="30" rows="2"></textarea></td>
</tr>
<tr>
<td valign="top" bgcolor="#E0E0E0"><span class="style3">เวลา
<input name="time_start<?=$d?>[]" type="text" id="textfield21" size="5" />
-
<input name="time_end<?=$d?>[]" type="text" id="textfield22" size="5" />
</span></td>
<td align="left" valign="top" bgcolor="#E0E0E0"><span class="style3">
<label>
<select name="amper_att<?=$d?>[]" id="amper_att<?=$d?>[]">
<?
$sql="select * from amper";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->amper_name?>"><?=$rs->amper_name?></option>
<? } ?>
</select>
</label>
</span></td>
<td align="left" valign="top" bgcolor="#E0E0E0"><label>
<select name="attraction<?=$d?>[]" id="select22">
<?
$sql="select * from attraction";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->attraction?>"><?=$rs->attraction?></option>
<? } ?>
</select>
</label></td>
<td align="left" bgcolor="#E0E0E0"><textarea name="note<?=$d?>[]" id="textarea8" cols="30" rows="2"></textarea></td>
</tr>
<tr>
<td valign="top" bgcolor="#E0E0E0"><span class="style3">เวลา
<input name="time_start<?=$d?>[]" type="text" id="textfield23" size="5" />
-
<input name="time_end<?=$d?>[]" type="text" id="textfield24" size="5" />
</span></td>
<td align="left" valign="top" bgcolor="#E0E0E0"><span class="style3">
<label>
<select name="amper_att<?=$d?>[]" id="select23">
<?
$sql="select * from amper";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->amper_name?>"><?=$rs->amper_name?></option>
<? } ?>
</select>
</label>
</span></td>
<td align="left" valign="top" bgcolor="#E0E0E0"><label>
<select name="attraction<?=$d?>[]" id="select24">
<?
$sql="select * from attraction";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->attraction?>"><?=$rs->attraction?></option>
<? } ?>
</select>
</label></td>
<td align="left" bgcolor="#E0E0E0"><textarea name="note<?=$d?>[]" id="textarea9" cols="30" rows="2"></textarea></td>
</tr>
<tr>
<td valign="top" bgcolor="#E0E0E0"><span class="style3">เวลา
<input name="time_start<?=$d?>[]" type="text" id="textfield25" size="5" />
-
<input name="time_end<?=$d?>[]" type="text" id="textfield26" size="5" />
</span></td>
<td align="left" valign="top" bgcolor="#E0E0E0"><span class="style3">
<label>
<select name="amper_att<?=$d?>[]" id="select25">
<?
$sql="select * from amper";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->amper_name?>"><?=$rs->amper_name?></option>
<? } ?>
</select>
</label>
</span></td>
<td align="left" valign="top" bgcolor="#E0E0E0"><label>
<select name="attraction<?=$d?>[]" id="select26">
<?
$sql="select * from attraction";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->attraction?>"><?=$rs->attraction?></option>
<? } ?>
</select>
</label></td>
<td align="left" bgcolor="#E0E0E0"><textarea name="note<?=$d?>[]" id="textarea10" cols="30" rows="2"></textarea></td>
</tr>
<tr>
<td valign="top" bgcolor="#E0E0E0"><span class="style3">เวลา
<input name="time_start<?=$d?>[]" type="text" id="textfield27" size="5" />
-
<input name="time_end<?=$d?>[]" type="text" id="textfield28" size="5" />
</span></td>
<td align="left" valign="top" bgcolor="#E0E0E0"><span class="style3">
<label>
<select name="amper_att<?=$d?>[]" id="select27">
<?
$sql="select * from amper";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->amper_name?>"><?=$rs->amper_name?></option>
<? } ?>
</select>
</label>
</span></td>
<td align="left" valign="top" bgcolor="#E0E0E0"><label>
<select name="attraction<?=$d?>[]" id="select28">
<?
$sql="select * from attraction";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->attraction?>"><?=$rs->attraction?></option>
<? } ?>
</select>
</label></td>
<td align="left" bgcolor="#E0E0E0"><textarea name="note<?=$d?>[]" id="textarea11" cols="30" rows="2"></textarea></td>
</tr>
</table></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" class="style3"><strong>กิจกรรมช่วงบ่าย</strong></td>
</tr>
<tr>
<td><table width="962" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" bgcolor="#009900" class="style10">ช่วงเวลา</td>
<td align="left" bgcolor="#009900"><span class="style10">อยู่ที่อำเภอ</span></td>
<td align="left" bgcolor="#009900"><span class="style10">สถานที่ท่องเที่ยว</span></td>
<td bgcolor="#009900" class="style10">กิจกรรมเพิ่มเติม</td>
</tr>
<tr>
<td width="178" valign="top"><span class="style3">เวลา
<input name="time_start<?=$d?>[]" type="text" id="textfield29" size="5" />
-
<input name="time_end<?=$d?>[]" type="text" id="textfield30" size="5" />
</span></td>
<td width="188" align="left" valign="top"><span class="style3">
<label>
<select name="amper_att<?=$d?>[]" id="select29">
<?
$sql="select * from amper";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->amper_name?>"><?=$rs->amper_name?></option>
<? } ?>
</select>
</label>
</span></td>
<td width="318" align="left" valign="top"><label>
<select name="attraction<?=$d?>[]" id="select30">
<?
$sql="select * from attraction";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->attraction?>"><?=$rs->attraction?></option>
<? } ?>
</select>
</label></td>
<td width="282" align="left"><textarea name="note<?=$d?>[]" id="textarea12" cols="30" rows="2"></textarea></td>
</tr>
<tr>
<td valign="top"><span class="style3">เวลา
<input name="time_start<?=$d?>[]" type="text" id="textfield31" size="5" />
-
<input name="time_end<?=$d?>[]" type="text" id="textfield32" size="5" />
</span></td>
<td align="left" valign="top"><span class="style3">
<label>
<select name="amper_att<?=$d?>[]" id="select31">
<?
$sql="select * from amper";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->amper_name?>"><?=$rs->amper_name?></option>
<? } ?>
</select>
</label>
</span></td>
<td align="left" valign="top"><label>
<select name="attraction<?=$d?>[]" id="select32">
<?
$sql="select * from attraction";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->attraction?>"><?=$rs->attraction?></option>
<? } ?>
</select>
</label></td>
<td align="left"><textarea name="note<?=$d?>[]" id="textarea13" cols="30" rows="2"></textarea></td>
</tr>
<tr>
<td valign="top"><span class="style3">เวลา
<input name="time_start<?=$d?>[]" type="text" id="textfield33" size="5" />
-
<input name="time_end<?=$d?>[]" type="text" id="textfield34" size="5" />
</span></td>
<td align="left" valign="top"><span class="style3">
<label>
<select name="amper_att<?=$d?>[]" id="select33">
<?
$sql="select * from amper";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->amper_name?>"><?=$rs->amper_name?></option>
<? } ?>
</select>
</label>
</span></td>
<td align="left" valign="top"><label>
<select name="attraction<?=$d?>[]" id="select34">
<?
$sql="select * from attraction";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->attraction?>"><?=$rs->attraction?></option>
<? } ?>
</select>
</label></td>
<td align="left"><textarea name="note<?=$d?>[]" id="textarea14" cols="30" rows="2"></textarea></td>
</tr>
<tr>
<td valign="top"><span class="style3">เวลา
<input name="time_start<?=$d?>[]" type="text" id="textfield35" size="5" />
-
<input name="time_end<?=$d?>[]" type="text" id="textfield36" size="5" />
</span></td>
<td align="left" valign="top"><span class="style3">
<label>
<select name="amper_att<?=$d?>[]" id="select35">
<?
$sql="select * from amper";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->amper_name?>"><?=$rs->amper_name?></option>
<? } ?>
</select>
</label>
</span></td>
<td align="left" valign="top"><label>
<select name="attraction<?=$d?>[]" id="select36">
<?
$sql="select * from attraction";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->attraction?>"><?=$rs->attraction?></option>
<? } ?>
</select>
</label></td>
<td align="left"><textarea name="note<?=$d?>[]" id="textarea15" cols="30" rows="2"></textarea></td>
</tr>
<tr>
<td valign="top"><span class="style3">เวลา
<input name="time_start<?=$d?>[]" type="text" id="textfield37" size="5" />
-
<input name="time_end<?=$d?>[]" type="text" id="textfield38" size="5" />
</span></td>
<td align="left" valign="top"><span class="style3">
<label>
<select name="amper_att<?=$d?>[]" id="select37">
<?
$sql="select * from amper";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->amper_name?>"><?=$rs->amper_name?></option>
<? } ?>
</select>
</label>
</span></td>
<td align="left" valign="top"><label>
<select name="attraction<?=$d?>[]" id="select38">
<?
$sql="select * from attraction";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->attraction?>"><?=$rs->attraction?></option>
<? } ?>
</select>
</label></td>
<td align="left"><textarea name="note<?=$d?>[]" id="textarea16" cols="30" rows="2"></textarea></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
</table></td>
</tr>
</table>
<? } ?>
<label>
<div align="left" class="style3">
<input name="pack_name" type="hidden" id="pack_name" value="<?=$_GET["pack_name"]?>" />
<input type="submit" name="submit" id="submit" value="เพิ่มรายการ" />
</div>
</label>
</form>
</body>
</html>
อยากให้ ตรงตาราง amper join กับ ตาราง attraction อ่าครับ
คือเมื่อเลือก อำเภอ นี้ ขึ้นสถานที่ท่องเที่ยวนี้ อ่าครับ
<select name="amper_att<?=$d?>[]" id="amper_att<?=$d?>[]">
<?
$sql="select * from amper";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->amper_name?>"><?=$rs->amper_name?></option>
<? } ?>
</select>
</label>
</span></td>
<td align="left" valign="top" bgcolor="#E0E0E0"><label>
<select name="attraction<?=$d?>[]" id="attraction<?=$d?>[]">
<?
$sql="select * from attraction";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->attraction?>"><?=$rs->attraction?></option>
<? } ?>
</select>
รบกวนท่านผู้รู้ด้วยครับ
ขอบคุณครับ :)Tag : PHP, MySQL
Date :
2010-10-09 13:33:26
By :
notz
View :
780
Reply :
5
Code (PHP)
$sql ="select * from amper,attraction where amper.id=attraction.id";
$result =mysql_query($sql) or die(mysql_error());
Date :
2010-10-09 16:26:42
By :
2m2n
ผมลองแล้ว มันขึ้น พร้อมกันหมดเลย คือประมานว่า
เลือกอำเภอไหนก้อมี สถานที่ท่องเที่ยวหมดทุกอันอ่า - -
ตางรางอำเภอ มี amper_id , amper_name
ตาราง attraction มี att_id , attraction , amper_name , amper_id
รบกวนด้วยครับ -.-
Date :
2010-10-09 17:09:20
By :
notz
ลองแบบนี้นะครับ
select * from table_name1 left outer join table_name2(ตารางที่ต้องการนำมา join) on field_name1 = field_name2
ส่วน where นั้นแล้วแต่คุณครับ
field_name1 คือ field ของ table_name1
field_name2 คือ field ของ table_name2
ลองดูนะครับ
Date :
2010-10-09 21:06:04
By :
kanchen
Code (PHP)
select*from ตารางอำเภอ INNER JOIN ตารางที่ท่องเที่ยว ON ตารางอำเภอ.amper_id=ตารางที่ท่องเที่ยว.amper_id
ลองแบบนี้ดูครับ
Date :
2010-10-09 21:54:27
By :
iieszz
Code (PHP)
<select name="amper_att<?=$d?>[]" id="amper_att<?=$d?>[]">
<?
$sql="select * from amper inner join attraction on amper.amper_id = attraction.amper_id";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->amper_name?>"><?=$rs->amper_name?></option>
<? } ?>
</select>
</label>
</span></td>
<td align="left" valign="top" bgcolor="#E0E0E0"><label>
<select name="attraction<?=$d?>[]" id="attraction<?=$d?>[]">
<?
$sql="select * from amper inner join attraction on amper.amper_id = attraction.amper_id";
$result = mysql_query($sql);
while($rs=mysql_fetch_object($result)) {
?>
<option value="<?=$rs->attraction?>"><?=$rs->attraction?></option>
<? } ?>
</select>
แบบนี้เป่าอ่าครับ ..
Date :
2010-10-09 22:08:02
By :
notz
Load balance : Server 05