Building a SQL query from another query in php

When I try to build a query from another query in php code, I run into some problem
can you tell me why? :(

the code:

$First="SELECT ro.RoomID,
               ro.RoomName,
               ro.RoomLogo,
               jr.RoomID,
               jr.MemberID,
               ro.RoomDescription 
          FROM joinroom jr,rooms ro 
         where (ro.RoomID = jr.RoomID)
           AND jr.MemberID = '1' ";

$sql1 = mysql_query($First);

$constract .= "ro.RoomName LIKE '%$search_each%'";
$constract="SELECT * FROM $sql1 WHERE $constract ";// This statment is Make error 

      

thanks, Query is working now! ..

But I faced another problem when I display the result of this query.

the code:

$run =mysql_query ($sql);

while($runrows=mysql_fetch_assoc($run))         
{
  $RoomName=$runrows["ro.RoomName"];
  $RoomDescription=$runrows["ro.RoomDescription"];

  echo "<center><b>$RoomName</b><br>$RoomDescription<br></center>";
}

      

+2


a source to share


2 answers


As for the last part of the error you are having, you need to remove the "ro" prefix. from the right-hand sides of the assignment operators.

So your actual code should have been: -



$run = mysql_query ($sql);
while($runrows = mysql_fetch_assoc($run)) {
    $RoomName = $runrows["RoomName"];
    $RoomDescription = $runrows["RoomDescription"];

    echo "$RoomName $RoomDescription";
}

      

Try this above and you should work well; until and until there is some error regarding the existence of your field in your database table or database connection.

+1


a source


You don't need a subquery to add the LIKE part:

SELECT ro.RoomID,ro.RoomName,ro.RoomLogo,jr.RoomID, jr.MemberID,ro.RoomDescription
FROM joinroom jr, rooms ro 
WHERE ro.RoomID = jr.RoomID
  AND jr.MemberID = '1'
  AND ro.RoomName LIKE '%$search_each%'
      



Btw, make sure you deactivate / remove the variable $search_each

.

0


a source







All Articles