Php newbie questions!

after applying your query i m getting this error Unknown column ‘s.id’ in ‘where clause’

Well, it was your query, from which I supposed that you have an id column in your subjects table.
But you can have different database design, of course

well what should i do? i m stuck

at least post here structure of your tables.

no tables. just div’s

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Staff</title>
<link href="Stylesheet/front.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div class="header">Widget Corp</div>
<div class="sidemenu">
    <ul>
<?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>";
}
?>
</ul>
</div>
<div class="main">
</div>
</body>
</html>

database tables I mean
“subjects” and “pages”

well i m a new at mysql i m using php my admin. i don’t know how to

  $sql = "SELECT * FROM subjects";
  $result = mysql_query($sql); 
  $subs = mysql_fetch_array($result);

  $sql = "SELECT * FROM pages";
  $result = mysql_query($sql); 
  $pages = mysql_fetch_array($result);

  echo "<pre>";
  print_r($subs);
  print_r($pages);
  echo "</pre>";

Put this code in your page and copy it’s output here

Array
(
[0] => 1
[int] => 1
[1] => About Widget Corp
[menu_name] => About Widget Corp
[2] => 1
[position] => 1
[3] => 1
[visible] => 1
)
Array
(
[0] => 1
[id] => 1
[1] => 1
[subject_id] => 1
[2] => History
[menu_name] => History
[3] => 1
[position] => 1
[4] => 1
[visible] => 1
[5] => This is the company history…
[content] => This is the company history…
)

Well you messed up with field names. You don’t have column ‘id’ in your subjects table, you named it ‘int’.
I’d suggest to correct it, using phpmyadmin

Ah! how foolish of me. thanks a ton! though i haven’t gotten my head around inplace subsitution. i believe that is what it is called. its a subsitution to concatenation.

For MySQL queries the (one of the two) best way(s) to do it is something like


$name = 'ScallioXTX';
$res = mysql_query('SELECT id,username,email FROM users WHERE username="'.mysql_real_escape_string($name).'"');

As mysql_real_escape_string() helps prevent [url=http://en.wikipedia.org/wiki/SQL_injection]SQL Injection.

The other way is to use prepared statements, but if I were you I’d start with mysql_real_escape_string and MySQL in general, and start looking at prepared statements when you feel comfortable with MySQL.

PS. Yes, I believe the term “inplace substitution” is correct, although it is not very commonly used IMHO.

i m following lynda.com tutorial and the guy uses the inplace sub and concatenation so much. its a essetional training and already i m started to getting confused

Can you tell what you mean by “inplace sub and concatenation”?
I’m not sure we’re talking abou the same thing(s) …

concatination is like

<?php echo ("<strong>" ."Hello world". "</strong>"); ?>

not sure how would u do it in inplace