Help I am getting a parse error on line 54

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joelitos
Forum Newbie
Posts: 10
Joined: Sun May 17, 2009 12:43 am

Help I am getting a parse error on line 54

Post 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']; 
 }
 }
 }
?>
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

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

Post by Ziq »

Are you sure that this is 54 line?

You have an error at this line
$smenu = mysql_query($sql2)
You forgot ;
charli18
Forum Newbie
Posts: 11
Joined: Tue May 19, 2009 3:35 am

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

Post 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);
joelitos
Forum Newbie
Posts: 10
Joined: Sun May 17, 2009 12:43 am

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

Post 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
Post Reply