[英]SQL inner Query not giving output
/* In $selected m getting data from java code which is successsfully getting stored in $selected. / *在$ selected中,从Java代码获取数据,该数据已成功存储在$ selected中。 Using $selected in query but cannot get any data after firing the query.
在查询中使用$ selected,但在触发查询后无法获取任何数据。 */
* /
$selected = $_GET['selected'];
$projects=mysql_query("select ProjectName from projects where LobID =
( select LobID from lob where LobName like ".$selected.");");
if (!$projects) {
echo "Could not successfully run query ($projects) from DB: " .mysql_error();
exit;
}
/* Have included this query in my php page. All the table names are same.Lob and projects are two different tables n LobID is primary key in Lob & Foreign key in projects. By executing the above query I am not able to fetch the data in $projects.Instead i am getting mesagecould not successfully run query. please help. */
Query should be like this 查询应该是这样的
$projects=mysql_query("select ProjectName from projects where LobID =
(select LobID from lob where LobName like '$selected')");
Change ".$selected.");
更改
".$selected.");
to '$selected'
到
'$selected'
Try this... If you use like to search LobName means use %% .Its retrun possible match value kike single character 试试这个...如果您喜欢搜索LobName,则表示使用%%。它会重新运行可能的匹配值,例如单个字符
"select ProjectName from projects where LobID =
( select LobID from lob where LobName like '%$selected%');"
I think it should be the mix of Jocker' and Abdulla Nilam' answer: 我认为这应该是乔克(Jocker)和阿卜杜拉·尼拉姆(Abdulla Nilam)的回答:
$projects=mysql_query("select ProjectName from projects
where LobID = ( select LobID from lob
where LobName like '%".$selected."%');");
or make a join 或加入
$projects = mysql_query("SELECT ProjectName FROM projects
JOIN lob ON projects.LobID=lob.LobID
WHERE LobName LIKE '%" . $selected . "%');");
$selected = $_GET['selected'];
$selected = $_GET['selected'];
包含的数据类型$selected = $_GET['selected'];
variable? if your subquery returns more records, you can either limit the number of results: 如果您的子查询返回更多记录,则可以限制结果数:
<?php /** ... **/ $selected = $_GET['selected']; $projects = mysql_query("SELECT ProjectName FROM projects WHERE (LobID = ( SELECT LobID FROM lob WHERE LobName LIKE '%$selected%' LIMIT 1))"); ?>
if not, you can do like this: 如果没有,您可以这样做:
<?php /** ... **/ $selected = $_GET['selected']; $projects = mysql_query("SELECT ProjectName FROM projects WHERE (LobID IN ( SELECT LobID FROM lob WHERE LobName LIKE '%$selected%'))"); ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.