【问题标题】:how to retrieve the data from two table in mysql database with if condition in php mysql如何使用php mysql中的if条件从mysql数据库中的两个表中检索数据
【发布时间】:2013-04-25 11:08:37
【问题描述】:

我的代码是

<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>

我想为 stud show 选择选项框条件以选择特定位置.. 请指导我如何使用 if 条件或 foreach 条件合并两个表

【问题讨论】:

  • 我认为您希望通过选择节目框来过滤位置框?
  • 另外,您在输出已经开始后执行 session_start。这应该在任何输出之前
  • 您应该尝试从前面的简短问题陈述开始您的问题。从数据和代码块开始,没有任何解释会让人难以阅读。也就是说,一个预期输出的例子会对这个问题有很大帮助。
  • 嗨,nvanesch 我正在使用 4 个组合框的依赖表,我得到了正确的三个组合依赖表,但第 4 个正在制造越来越多的麻烦

标签: php mysql if-statement for-loop


【解决方案1】:

对于严格匹配:

    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)

【讨论】:

    猜你喜欢
    • 2012-12-09
    • 1970-01-01
    • 1970-01-01
    • 2014-10-28
    • 2016-08-17
    • 2014-04-10
    • 2020-05-11
    • 1970-01-01
    • 2015-12-03
    相关资源
    最近更新 更多