Query error (inplace subsitutio )

hey folks, as i m moving towards my php learning joruney i m facing another probelm. i got the idea of concatination but i m unable to follow inplace subsitution (the curly braces replacement for .) here is a query i m following from a tutorial but something is wrong after WHERE. can anyone help me. its giving me error

$result= mysql_query("SELECT * FROM pages WHERE  subject_id = {$row["id"]}");

This is no mysql problem, but a PHP one.
You’re using double quotes inside a string delimited by double quotes. Try single quotes:


$result= mysql_query("SELECT * FROM pages WHERE  subject_id = {$row['id']}");

i tired but still same error

What is the error?

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’ at line 1.
here is the complete php

<?php 
    $result= mysql_query("SELECT * FROM subjects");
    if(!$result){
        die  ("<strong>". mysql_error() ."</strong>");
    }
    while ($row = mysql_fetch_array($result)){
    echo "<li>".$row["menu_name"] ."</li>";
        //echo pages related to subjects
            $result= mysql_query("SELECT * FROM pages WHERE subject_id = {$row['id']}");
            if(!$result){
            die  ("<strong>". mysql_error() ."</strong>");
        }
        echo "<ul class=\\"pages\\">";
        while ($row = mysql_fetch_array($result)){
        echo "<li>".$row["menu_name"] ."</li>";
        }
        echo "</ul>";
}
?>

Try this:


  $query = "SELECT * FROM pages WHERE  subject_id = {$row['id']}";
echo "query: $query <br />";
  $result= mysql_query($query); 

And see what the echo displays.

it gave me output of query string printed out?

:rolleyes:
Could you please share the output with us?

don’t run a query and then run another one inside a loop for each returned id – use a join query instead