2

When I Try to built Query from another Query in php code I Faced some problem
can you tell me why? :(

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 it is Work now ! ..

But I Faced another problem ,When I Display the Result of this Query ..

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

2

Regarding the last part of the error, which you are facing, you need to remove the prefix "ro." from the right hand parts of the assignment statements.

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 one above, & you should be working fine; until & unless there is some error regarding your field's existence in your database table or your database connection.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank ! it's Working well now! : )
Thanks to you, for testing it quick enough & setting it as the answer.
0

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 to sanitize/escape the $search_each variable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.