SitePoint Sponsor

User Tag List

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

    Thumbnail linking to an specific position to a looped <ul>

    I found this link to olive Garden http://www.olivegarden.com/menus/ which it has resemblance to what I want to achieved.

    If you check at the bottom of the page there are four thumbnails with one image and some text align="center" each.


    1. Lunch Menu
    2. Dinner Menu
    3. Beverage Menu
    4. Dessert Menu

    Now to the left of the web page you will see a <ul> list with a heading call Our Menu the list looks similar to the one below


    1. Specials
    2. Lunch
    3. Dinner
    4. Beverage
    5. To go!
    6. Dessert


    If you click on the Lunch Menu Thumbnail at the bottom of the web page, you will realize that it will link you to a page that open the Lunch heading of the <ul> list, displaying all the subheadings within the Lunch heading.

    My question is how that achieved?

    I know that through the link of the thumbnails the user is directed to a page where it get to activate the while loop embed in the <ul> list to display the subheadings within the Lunch heading line in the <ul> list.

    My question could that be achieved?

    How many queries would be needed to achieve this requests and effects? how this queries would look like?


    And the most important of all How I would get the while loop in the <ul> list to display only the subheadings of the heading being refered to, from the thumbnail link? I know it would be like referring to an specific position inside of the array of the while loop in the <ul> list but how or something similar or maybe there is another way not sure. I just been having difficulties to putting it together.

    This is the code I have so far, it has an looped <Ul> list and a looped <table></table> which display the thumbnails.

    PHP Code:

    $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 

    $sql = "SELECT menusubjects.Subjectmenusubjects.image
      FROM menusubjects
    "; 
    $result = mysql_query($sql$connection);
    if(!
    $result){
      die("
    Database query failed:" . mysql_error());}
    while (
    $content = mysql_fetch_array($result)) {
      echo "
    <table width=\"260\" height=\"100\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#FF0033\" bgcolor=\"#FFFFFF\" style=\"float:left; position:relative; left:206px; top:
      300px; height:5px;\">
      <td width=\"95%\ height=\"10%\"> <table width=\"96%\" height=\"10%\"> <td style=\"width:100%\"><img src=\"../images/lineforheader.gif\" alt=\"gf\" width=\"100%\" /></td><tr><td bordercolor=\"#666666\" bgcolor=\"#D83607\" height=\"100%\" style=\" width:140px;\"><a href=\"#\">
          <div class=\"shoe2\" align=\"left\" style=\"background-image:url(../images/titleshoe.gif);\">" 
    $content['Subject'] . "</div>
        </a></td></tr>
        <tr>
          <td  style=\"width:100%; background:#CC0000; height:2px;\"><a href=\"#\">" 
    $content['image'] . "</a></td>
        </tr></table></td>
      </table></td>"
    ;
      } 
    Last edited by co.ador; May 18, 2009 at 19:20.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this is what you want to do??

    say the link was: http://example.com/menu.php?menu_type=lunch

    then
    PHP Code:
    $menu_type $_GET['menu_type'];

    $menu //query menu table
    $submenu // query the submenu table/whatever

    // display each menu entry
    while($m mysql_fetch_array($menu)) {
        echo 
    $m['name'];
        
    // if the submenu requested is the same as this menu
        
    if($m['name'] == $menu_type) {
            
    // display submenu names
            
    while($s mysql_fetch_array($submenu)) {
                echo 
    $s['name'];
            }
        }


  3. #3
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Hash, I have some homework to do. I appreciate it, I will try to complete the code you did.

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

    What would be the value of menu_type here?

    PHP Code:
    $menu_type $_GET['menu_type']; 

  5. #5
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks you,
    Now I have an idea on how to direct a link through the thumbnail, But still I want that once I click on the thumbnail it opens the first heading of the <ul> list.

    click in the thumbnails Lunch menu and then it opens the Lunch <ul> list.

    But this code will only display the submenus if I click in the <ul> list but instead of opening from the thumbnails at once all.

    Is there a code that opens query without users having to click on?

  6. #6
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can anybody bring some thoughts?

    to direct me in the right path
    What topic do you advice me to read from the php manual so I can read to help me figure this out?

    I will appreciate any help please..

    Thank you

  7. #7
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    from a url like
    Code:
    www.example.com/index.php?type=lunch&day=monday&something=athing
    lunch, monday etc appear in the $_GET array. So $_GET['day'] will be 'monday'

    link from a thumbnail, the menu, whatever, but once you pass in the variable, eg 'lunch' you then know to display the lunch menu: if($_GET['type'] == 'lunch')

  8. #8
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understood where the value of
    PHP Code:
    $menu_type $_GET['menu_type']; 
    comes from thank you.

    But I still have a couples of questions about what you have explained me, you will excuse me but if my questions sound kind of childish I still newbie to php.

    Does the thumbnail link could look something like this?
    PHP Code:
    $uri3 "example1.php?manu_type=".urlencode($content['Subject']);

    <
    td><a href=\"$uri3\">
          <div class=\"letras2\" align=\"left\" style=\"background-image:url(../images/titleshoe1.gif);\">" 
    $content['Subject'] . "</div>
        </a></td> 

    The code below is what you gave in your first response to this thread, this would in the document where the thumbnails are? or in the document where the thumbnails are liking to?
    PHP Code:
    $menu_type $_GET['menu_type'];

    $menu //query menu table

    $submenu // query the submenu table/whatever



    // display each menu entry

    while($m mysql_fetch_array($menu)) {

        echo 
    $m['name'];

        
    // if the submenu requested is the same as this menu

        
    if($m['name'] == $menu_type) {

            
    // display submenu names

            
    while($s mysql_fetch_array($submenu)) {

                echo 
    $s['name'];

            }

        }


    you said "link from a thumbnail, the menu"
    you also said Once you pass in the variable, Which variable?

    And where does lunch menu: if($_GET['type'] == 'lunch') would be placed and in which file? in the menu file or the where the thumbnails are?

  9. #9
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by co.ador View Post
    Does the thumbnail link could look something like this?
    Yes, well that code won't work, but that's the idea.

    Quote Originally Posted by co.ador View Post
    The code below is what you gave in your first response to this thread, this would in the document where the thumbnails are? or in the document where the thumbnails are liking to?
    Well that code displays the menu, I left out all the <ul> etc, so it goes in the page you are linking to.

    Quote Originally Posted by co.ador View Post
    you said "link from a thumbnail, the menu"
    you also said Once you pass in the variable, Which variable?
    Link from anywhere, here for example www.xyz.com/index.php?type=lunch
    lunch is the variable passed in to the page you are linking to.

    Quote Originally Posted by co.ador View Post
    And where does lunch menu: if($_GET['type'] == 'lunch') would be placed and in which file? in the menu file or the where the thumbnails are?
    Well in that example, you want to display the lunch menu if they clicked on lunch. So that would be in the menu. It's the same as
    PHP Code:
    $menu_type $_GET['menu_type'];
    // ... 
    // if the submenu requested is the same as this menu
    if($m['name'] == $menu_type) {
         
    // display submenu names 

  10. #10
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Link from anywhere, here for example www.xyz.com/index.php?type=lunch
    lunch is the variable passed in to the page you are linking to.
    You said that Lunch is the variable passed in to the page I am liking to, Which I understand that I can create one page and depending on the variable passed then the page I am liking to will take that variable and perform it's codes and queries according to the value of the variable from the previous page.

    if that's how it works it is awesome!!!!!!!!!!

    finally i have understood some basics.

    I appreciate your explanations hash and all of yours guys.

  11. #11
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have put this queries together. but i am getting a parse error on line 54 but I don't know what it could be.

    PHP Code:
    $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']; 
     }
     }
     }
    ?> 


    help...

  12. #12
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    problem is with the line below that one, also if($rod ... should be if($row... ?

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

    Can you explain me what does this mean?

    PHP Code:
    $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 


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
  •