SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Display issues!

  1. #1
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Display issues!

    Guys I am facing a display problem which I know it will be resolved with a If else statement or some condition of that kind.
    I want that if user x click one of the submenus of the first query at or first display then user x will be able to see only first display layout below the while loop and if user x click in the subjects second display then user x will be able to see only the layout in the second display and not both how it is displaying now. as I said before right now the way it is working is that if user x click on one of the submenu in the first display then the layout of the first display appear and the layout of the second display as well and I only want it to show the one the user required first layout or second layout depending where the user clicked in other word "one at the time".Right now when user x click on the subjects 'second display layout' or Subjects menu then the layout of the second display appear this time not both together I guess becuase after the second query there is not more coding.

    Can you help me to display one at the time e.g if user x clicked on the subject menu then only the layout of subject menu will appear or if user x clicked on the submenu menu then only the layout of the submenu menu will appear.

    help please.
    PHP Code:
    <?php

    $submenu 
    false;
    $cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null;
    $prod = isset($_GET['menu']) && is_numeric($_GET['menu'])?$_GET['menu']:null;
    $menu_type = isset($_GET['menu_type']) && is_string($_GET['menu_type'])?$_GET['menu_type']:null
    ?>

    //First Display
    <?php 
    $query 
    "SELECT id, submenus, image,
    FROM submenu
    WHERE
    id= " 
    . (int) $_GET['menu']; 
    echo 
    $query;
    $result mysql_query($query$connection); 
     while (
    $content mysql_fetch_array($result)) {
    echo 
    '<table border="0" cellspacing="0" cellpadding="0">
    <td>Something</td></table>'
    ;
    }
    ?>

    // second display
    <?php 
    $query2 
    "SELECT id, Subject, image,
    FROM subjects
    WHERE
    id= " 
    . (int) $_GET['subject']; 
    echo 
    $query2;
    $result2 mysql_query($query2$connection); 
      {
    echo 
    '<table border="0" cellspacing="0" cellpadding="0" >
    <td></td>
    </table>'
    ;
    }
    ?>
    Sorry about the real former mess.

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    It still amazes me when I hear a simple logic question, yet the code which seems to be 90&#37; crappy old html which we are supposed to willingly wade through.

    If you were able to distill this down to a simple example you could expand it back into your own script when you get an answer?

    That question needs some careful thought too, I am not going to read it.

  3. #3
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry For the mess i did before now it's more readable...

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Thanks for responding, I have re-read your question, and still don't get it though.

    Is this what you mean, build a query and make it conditional on whether menu or subject is set?
    PHP Code:
    <?php

    $submenu 
    false;

    // decide which is the correct query

    if( isset($_GET['menu']) ){

    $query "SELECT id, submenus, image,
    FROM submenu
    WHERE
    id= " 
    . (int) $_GET['menu']; 

    }elseif( isset( 
    $_GET['subject']) ) {

    $query "SELECT id, Subject, image,
    FROM subjects
    WHERE
    id= " 
    . (int) $_GET['subject']; 

    }else{
    // if neither is set, do what?

    }

    // take a look at which was chosen
    echo $query ;

    // then deal with the query and display the table

    $result mysql_query($query$connection); 
      {

      echo 
    '<table border="0" cellspacing="0" cellpadding="0" >
      <td></td>
    </table>'
    ;

    }

    ?>
    Bear in mind the limitations of isset() as outlined here. If it doesn't work as planned then var_dump( $_POST ) to see what you are testing against.

    If each table is different then you'll have to move some or all of the table creation into the if() clauses.

  5. #5
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes there are two queries as seen above and both tables have different layouts.

    the code that links to one or the other goes as below


    PHP Code:
    <?php   
      $sql 
    'SELECT id,Subject FROM subjects;';
      
    $result mysql_query($sql);

    if(
    $result && mysql_num_rows($result)!=0) {
       
        echo 
    '<ul class="nav-categories">';
        
        while(
    $row mysql_fetch_assoc($result)) {
        
            
    $uri 'example.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']) {
                    
                
    $sql2 'SELECT id,shoename FROM subemenumenu 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 $uri2.'&menu='.urlencode($row2['id']);
                        
    $class2 = !is_null($prod) && $prod==$row2['id']?' class="selected"':'';
                        
                        echo 
    "\t\t\t",'<li',$class2,'><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 whole code together would go like this
    PHP Code:
    <?php

    $submenu 
    false;
    $cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null;
    $prod = isset($_GET['menu']) && is_numeric($_GET['menu'])?$_GET['menu']:null;
    $menu_type = isset($_GET['menu_type']) && is_string($_GET['menu_type'])?$_GET['menu_type']:null
    ?>

         
    <?php   
      $sql 
    'SELECT id,Subject FROM subjects;';
      
    $result mysql_query($sql);

    if(
    $result && mysql_num_rows($result)!=0) {
       
        echo 
    '<ul class="nav-categories">';
        
        while(
    $row mysql_fetch_assoc($result)) {
        
            
    $uri 'example.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']) {
                    
                
    $sql2 'SELECT id,shoename FROM subemenumenu 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 $uri2.'&menu='.urlencode($row2['id']);
                        
    $class2 = !is_null($prod) && $prod==$row2['id']?' class="selected"':'';
                        
                        echo 
    "\t\t\t",'<li',$class2,'><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";
    }

       
     
     
    ?>

    //First Display
    <?php 
    $query 
    "SELECT id, submenus, image,
    FROM submenu
    WHERE
    id= " 
    . (int) $_GET['menu']; 
    echo 
    $query;
    $result mysql_query($query$connection); 
     while (
    $content mysql_fetch_array($result)) {
    echo 
    '<table border="0" cellspacing="0" cellpadding="0">
    <td>Something</td></table>'
    ;
    }
    ?>

    // second display
    <?php 
    $query2 
    "SELECT id, Subject, image,
    FROM subjects
    WHERE
    id= " 
    . (int) $_GET['subject']; 
    echo 
    $query2;
    $result2 mysql_query($query2$connection); 
      {
    echo 
    '<table border="0" cellspacing="0" cellpadding="0" >
    <td></td>
    </table>'
    ;
    }
    ?>

    I will test your variations let me see.

  6. #6
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Cups..


    I understand what you did it's good if both queries would have the same table I guess, but in this case both queries has different tables and layouts.

    you mentioned


    If each table is different then you'll have to move some or all of the table creation into the if() clauses.
    Can you make a little illustration to see how would it go two different queries each one with different tables and just one layout will be displayed depending on what query the user x clicked.

    again the code below is what links the user to what he wants to see the Subjects
    PHP Code:
    $uri 'example.php?subject='.urlencode($row['id']); 
    or the Submenu
    PHP Code:
    $uri2 $uri2.'&menu='.urlencode($row2['id']); 
    this two links will active the queries depending on weather the
    PHP Code:
    . (int) $_GET['subject']; 
    or
    PHP Code:
    . (int) $_GET['menu']; 
    Entire that links users to the queries.
    PHP Code:
    <?php   

      $sql 
    'SELECT id,Subject FROM subjects;';

      
    $result mysql_query($sql);
    if(
    $result && mysql_num_rows($result)!=0) {
           echo 
    '<ul class="nav-categories">';
        while(
    $row mysql_fetch_assoc($result)) {

       
    $uri 'example.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']) {
                
    $sql2 'SELECT id,shoename FROM subemenumenu 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 $uri2.'&menu='.urlencode($row2['id']);
                        
    $class2 = !is_null($prod) && $prod==$row2['id']?' class="selected"':'';                    
                        echo 
    "\t\t\t",'<li',$class2,'><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";
    }
     
    ?>

  7. #7
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have been trying to place the tables inside the if() parentheses but has work so far...

  8. #8
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cups This is what I was looking for


    PHP Code:
    <?php

    $submenu 
    false;
    $cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null;
    $prod = isset($_GET['menu']) && is_numeric($_GET['menu'])?$_GET['menu']:null;
    $menu_type = isset($_GET['menu_type']) && is_string($_GET['menu_type'])?$_GET['menu_type']:null

    if ($prod){


    $query "SELECT id, submenus, image,
    FROM submenu
    WHERE
    id= " 
    . (int) $_GET['menu']; 


    echo 
    $query ;

    $result mysql_query($query$connection); 
      {

      echo 
    '<table border="0" cellspacing="0" cellpadding="0" >
      <td>different</td><td>different</td>
    </table>'
    ;


    }
    elseif( 
    $cat) {

    $query "SELECT id, Subject, image,
    FROM subjects
    WHERE
    id= " 
    . (int) $_GET['subject']; 

    echo 
    $query ;

    $result mysql_query($query$connection); 
      {

      echo 
    '<table border="0" cellspacing="0" cellpadding="0" >
      <td></td>
    </table>'
    ;


    }
    ?>

    Check it out I didn't express it well at the beginning.

    Now if ($prod) is set then table x will appear or if ($cat) is set then table x will appear...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •