Reputation: 1
as the title said, i've this block of code and i want to know if i can write a variable that takes the name of another one similar to it but outside the loop.
is that makes a problem ?!
<?php
$query = "SELECT * FROM subjects";
$subjects_set = mysql_query($query);
errors_of($subjects_set);
while ($db_subjects_rows = mysql_fetch_array($subjects_set)){
echo "<li>{$db_subjects_rows["menu_name"]}</li>";
$pages_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$db_subjects_rows["id"]}");
errors_of($pages_set);
echo "<ul class=\"pages\">";
while ($db_pages_rows = mysql_fetch_array($pages_set)){
echo "<li>{$db_pages_rows["menu_name"]}</li>";
}
echo "</ul>";
}
?>
Upvotes: 0
Views: 1136
Reputation: 5191
All the variables that is used outside
the loop can be accessed inside
the loop.Refer this manual to know more about the PHP Variable Scope.
Upvotes: 1
Reputation: 8704
Using local variables inside a loop does not create a problem, if thats what you are asking, you should read about variable scopes
The function has a scope, the class has a scope and there is a global scope
Upvotes: 2