2013-04-25 31 views
-1

table design 如何與檢索兩個表中的數據在MySQL數據庫中,如果在PHP MySQL的條件

我的代碼是

<html> 
<head> 
<body> 
<div style="width:400px;height:300px;border:1px solid blue;"> 
<div style="width:400px;height:50px; float: left;">&nbsp;</div> 
<form> 
<div align="right" style="width:150px;height:30px; float: left;">Show Name :&nbsp; </div> 
<div style="width:250px;height:30px; float: left;"> 
<select name="show_name" onchange="showUser(this.value)"> 
<option selected="selected"> -- Select The Show --</option> 
<?php 
session_start(); 
include_once('db.php'); 
$sql = mysql_query("SELECT show_id, show_name FROM show_name"); 
while($row=mysql_fetch_array($sql)) 
{ 
$show_id = $row['show_id']; 
$show_name= $row['show_name']; 
echo "<option value ='.$show_id'>$show_name</option>"; 
} 
?> 
</select> 
</div> 
<div align="right" style="width:150px;height:30px; float: left;">Show Place :&nbsp;  </div> 
<div style="width:250px;height:30px; float: left;"> 
<select name="show_place" onchange="showUser(this.value)"> 
<option selected="selected"> -- Select The Show Place --</option> 
<?php 
$sql = mysql_query("SELECT * FROM show_name, show_place WHERE show_name.show_id=show_place.show_id"); 
while($row=mysql_fetch_array($sql)) 
{ 
$show_id = $row['show_id']; 
$show_place = $row['show_place']; 
echo "<option value ='.$show_id'>$show_place</option>"; 
} 
?> 
</select> 
</div> 
</form> 
</div> 
</body> 
</head> 
</html> 

我想選項框條件雙頭顯示,選擇特定的地方。 。請指導我如何合併兩個表使用,如果條件或條件的foreach

+0

我想你想的地方框由顯示框的選擇進行過濾? – nvanesch 2013-04-25 11:18:23

+0

另外,你在輸出已經開始之後做一個session_start。這應該在任何輸出之前 – nvanesch 2013-04-25 11:25:51

+0

您應該嘗試用一個簡短的問題陳述開始您的問題。從數據和代碼塊開始,沒有任何解釋使得硬讀。這就是說,預期產出的一個例子會對這個問題有很大的幫助。 – MvG 2013-04-25 14:29:36

回答

0

嚴格匹配:

SELECT * 
    FROM show_name 
    JOIN show_place ON (show_name.show_id = show_place.show_id) 

或者,如果你想沒有名字的地方太多:

SELECT * 
    FROM show_name 
    LEFT JOIN show_place ON (show_name.show_id = show_place.show_id) 
相關問題