/* In $selected m getting data from java code which is successsfully getting stored in $selected. Using $selected in query but cannot get any data after firing the query. */
$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.");
to '$selected'
Try this... If you use like to search LobName means use %% .Its retrun possible match value kike single character
"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:
$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'];
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%'))");
?>
</div>