Page 1 of 1

Help I am getting a parse error on line 54

Posted: Tue May 19, 2009 8:44 am
by joelitos

Code: Select all

 
$sql = "SELECT id,Subject FROM menusubjects";
$menu = mysql_query($sql);
while($row = mysql_fetch_assoc($menu)){
echo $row['Subject'];
if ($rod['Subject'] == $menu_type)
 {
 $sql2 = "SELECT * FROM regularmenu WHERE menusubjects ='$menu_type'"; //line 54
$smenu = mysql_query($sql2)
 while (srow = mysql_fetch_assoc($smenu)) {
 echo $smenu['shoename']; 
 }
 }
 }
?>

Re: Help I am getting a parse error on line 54

Posted: Tue May 19, 2009 8:52 am
by Ziq
Are you sure that this is 54 line?

You have an error at this line
$smenu = mysql_query($sql2)
You forgot ;

Re: Help I am getting a parse error on line 54

Posted: Tue May 19, 2009 8:53 am
by charli18
joelitos wrote:

Code: Select all

 
$sql = "SELECT id,Subject FROM menusubjects";
$menu = mysql_query($sql);
while($row = mysql_fetch_assoc($menu)){
echo $row['Subject'];
if ($rod['Subject'] == $menu_type)
 {
 $sql2 = "SELECT * FROM regularmenu WHERE menusubjects ='$menu_type'"; //line 54
$smenu = mysql_query($sql2)
 while (srow = mysql_fetch_assoc($smenu)) {
 echo $smenu['shoename']; 
 }
 }
 }
?>
# $sql2 = "SELECT * FROM regularmenu WHERE menusubjects =$menu_type "; //line 54
# $smenu = mysql_query($sql2);

Re: Help I am getting a parse error on line 54

Posted: Tue May 19, 2009 12:45 pm
by joelitos
now it works
online 55 I was missing the dollar sign at the variable $smenu

Code: Select all

$smenu = mysql_query($sql2);
online 54 I needed to take the qoutes around the $menu_type variable

Code: Select all

$sql2 = "SELECT * FROM regularmenu WHERE menusubjects =$menu_type";
I am trying to pass the value of the variable $menu_type from a page that links a user to a new one, that contain the queries we've been trying to fix through the entire thread together.

working draft..

Code: Select all

$cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null;
$prod = isset($_GET['menu']) && is_numeric($_GET['menu'])?$_GET['menu']:null;
$menu_type = $_GET['menu_type'];
 
$sql = "SELECT id,Subject FROM menusubjects";
$menu = mysql_query($sql);
while($row = mysql_fetch_assoc($menu)){
echo $row['Subject'];
if ($row['Subject'] == $menu_type)
 {
 $sql2 = "SELECT * FROM regularmenu WHERE menusubjects ='$menu_type'"; //line 54
$smenu = mysql_query($sql2);
 while ($srow = mysql_fetch_assoc($smenu)) {
 echo $srow['shoename']; 
 }
 }
 }
?>
The values of the $menu_type variable are echoing horizontally in the new page instead of vertically form as it supposed to be in the queries below.

Code: Select all

 
$cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null;
$prod = isset($_GET['menu']) && is_numeric($_GET['menu'])?$_GET['menu']:null;
$menu_type = $_GET['menu_type'];
 
$sql = 'SELECT id,Subject FROM menusubjects;'; 
$result = mysql_query($sql); 
if($result && mysql_num_rows($result)!=0) {   
    echo '<ul id="nav-categories">';  
    while($row = mysql_fetch_assoc($result)) {         
      $uri = 'example1.php?subject='.urlencode($row['id']); 
        $class = !is_null($cat) && $cat==$row['id']?' class="selected"':'';         
        echo "\t",'<li',$class,'><a href="',$uri,'">',$row['Subject'].'</a>';             
        if($submenu==false && !is_null($cat) && $cat == $row['id']) { // line 58                  
            $sql2 = 'SELECT id,shoename FROM regularmenu WHERE menusubject_id = '.mysql_real_escape_string($cat).';'; 
            $result2 = mysql_query($sql2);                
            if($result2 && mysql_num_rows($result2)!=0) {                      
                echo "\n\t\t",'<ul class="submenu">',"\n";                      
                while($row2 = mysql_fetch_assoc($result2)) {                      
                    $uri2 = $uri.'&menu='.urlencode($row2['id']); 
                    $class2 = !is_null($prod) && $prod==$row2['id']?' class="selected"':'';                      
                    echo "\t\t\t",'<li',$class,'><a href="',$uri2,'">',$row2['shoename'],'</a></li>',"\n";                 
                }                  
                echo "\t\t",'</ul> <!-- end of ul.submenu -->',"\n";                          
            }                 
            $submenu = true;              
        }              
        echo '</li>',"\n";          
    }          
    echo '</ul> <!-- end of ul#nav-categories -->',"\n
the new code I have post above display a menu which contains heading and subheadings below the subjects. within the last code which is the same as the one we have been discussing but with slightly differences. The differences are the <ul> tags

Code: Select all

echo '<ul id="nav-categories">'
This <ul> display the headings downward and it's subheadings as well, it has links for the headings and subheadings

Code: Select all

$uri = 'example1.php?subject='.urlencode($row['id']);
,
and some comparisons such as, if a heading is clicked on then display the submenus and leave them displayed,

Code: Select all

if($submenu==false && !is_null($cat) && $cat == $row['id'])[[php]
  I want to place within the new code an if condition statement like [php]if ($row['Subject'] == $menu_type)
where the $menu_type value comes from another page and only opens it's respective heading. for instance.

$menu_type value coming from another page == to $row['Subject] in the page being linked to then echo the submenus.

Previous page:

$menu_type= "Lunch"

Page where the user has been linked
$row = "Lunch"

then take that $menu_type == $row and echo the submenus of Lunch.

How can fit a condition?

Where in this code?

Code: Select all

 
$cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null;
$prod = isset($_GET['menu']) && is_numeric($_GET['menu'])?$_GET['menu']:null;
$menu_type = $_GET['menu_type'];
 
$sql = 'SELECT id,Subject FROM menusubjects;'; 
$result = mysql_query($sql); 
if($result && mysql_num_rows($result)!=0) {   
    echo '<ul id="nav-categories">';  
    while($row = mysql_fetch_assoc($result)) {         
      $uri = 'example1.php?subject='.urlencode($row['id']); 
        $class = !is_null($cat) && $cat==$row['id']?' class="selected"':'';         
        echo "\t",'<li',$class,'><a href="',$uri,'">',$row['Subject'].'</a>';             
        if($submenu==false && !is_null($cat) && $cat == $row['id']) { // line 58                  
            $sql2 = 'SELECT id,shoename FROM regularmenu WHERE menusubject_id = '.mysql_real_escape_string($cat).';'; 
            $result2 = mysql_query($sql2);                
            if($result2 && mysql_num_rows($result2)!=0) {                      
                echo "\n\t\t",'<ul class="submenu">',"\n";                      
                while($row2 = mysql_fetch_assoc($result2)) {                      
                    $uri2 = $uri.'&menu='.urlencode($row2['id']); 
                    $class2 = !is_null($prod) && $prod==$row2['id']?' class="selected"':'';                      
                    echo "\t\t\t",'<li',$class,'><a href="',$uri2,'">',$row2['shoename'],'</a></li>',"\n";                 
                }                  
                echo "\t\t",'</ul> <!-- end of ul.submenu -->',"\n";                          
            }                 
            $submenu = true;              
        }              
        echo '</li>',"\n";          
    }          
    echo '</ul> <!-- end of ul#nav-categories -->',"\n
any suggestions