Fork me on GitHub

DropDown menu  Bottom

  • Hi, is it possible to have on the front page a dropdown menu showing all users of a postnuke website? And is it possible that it changes dinamically adding all new users?

    If its of any help, I am using AutoTheme. Thanks!
  • The AutoTheme module won't help, but you could do that with some fairly simple PHP code. What would be the purpose of the drop-down and what would happen if you selected a particular person?
  • Can I toss in my 2 cents?

    Long drop down lists are a pain in the butt! If you have more than, say 50 users, I'd abandon this idea. Actually I'd abandon it anyway but, if you feel it's what you want to do, I recommend you keep it small.

    Also, keep in mind that the more often you query your database the greater the overhead and the more sluggish* your site will feel.

    Slugger

    * no relation! wink
  • Dunno why the hell you would want this, but here you go:

    Code

    <?php
    list($dbconn) = pnDBGetConn();
    $pntable =& pnDBGetTables();
       
    $column = &$pntable['users_column'];
    $sql = "SELECT * FROM $pntable[users]";
           
    $result =& $dbconn->Execute($sql);

    echo '<form name="form1"><div><select name="menu1">';                          
    while(!$result->EOF)
    {   
        $name = $result->fields[2]
        echo '<option>'.$name.'</option>';
        $result->MoveNext();
    }
    echo '</select></div></form>';
    ?>


    Just place this code anywhere in your theme - note it doesn't have permission checks so it will come up for all users (it is wasy to add permission checks to it if you need).

    -Lobos

    --
    -Lobos
    Professional PHP Framework Services: Concept, Development and Deployment
  • Hi thanks all for reply, and for comments that are always accepted a lot!

    Well the story is this. I am building a website where the only modules there are a diary and a PhotoGallery. So there isnt any content, just users can write diaries and write comments on others diary. Exactly like a kind of blogging system. Now, because users interact a lot with the other users, I would like to have a Handy user selector on each page which will bring you to the user page(i am using advprofile). Users are already 150, and I know that is not a good solution, but I havent found any better one. I would be glad if you can suggest me something different.

    Thanks again for the answers!
  • YOu should be able to modify the snippet I gave you to do this - you can bring up any of the fields from the users table with this snippet:

    $name = $result->fields[2];

    $userid = $result->fields[0];

    etc, etc

    now I am sure the advprofile must have a variable in the URL to define a unique user - it will just be a matter of finding this and adding the appropriate HTML / variables to the snippet I supplied.

    OR if you feel you cannot do this or can't be bothered I can make it happen for $US30.00 - just send a detailed explaination of your requirements to info [at] webvida.com and $30 via www.paypal.com to sales [at] webvida.com

    Thanks :)

    Have fun !

    -Lobos

    --
    -Lobos
    Professional PHP Framework Services: Concept, Development and Deployment
  • Thanks a lot and I am sorry, unfortunately i am really really poor at the moment. cry A lot of time i would love to just pay and make other people do the job, but i am poor so i have to do all myself, and given that i am really crap in PHP as i have started now, i am really on a bad position.

    So. If its possible without bothering. i have 2 question.

    First. How do i set a value to be shown as default.
    I know how to do in HTML but in PHP i dont know.

    Second. The sintax to go to advprofile is like this:
    module=advProfile&uname=

    where username is exactly what is shown on the dropdown with the code you gave me.

    I would really be glad if you could help me, and i wish that if i get into more troubles i would have the manney to make you do the job.

    Thanks again!
  • In the default option tag you have a parameter "selected". For instance:

    <option selected="selected">value</option>

    You'd need some extra code if you're going to look for a specific value to make selected - an if to check for a certain value.

    <select name="uname"> will get the value sent throught the form as uname, if that helps.

    Frank

    Frank</select>
  • So this is what i have done so far:

    between the head tag:

    Code

    <script language="JavaScript"><!--

    // ***********************************************
    // AUTHOR: WWW.CGISCRIPT.NET, LLC
    // URL: http://www.cgiscript.net
    // Use the script, just leave this message intact.
    // Download your FREE CGI/Perl Scripts today!
    // ( http://www.cgiscript.net/scripts.htm )
    // ***********************************************

    function goThere(form){
        var linkList=form.selectThis.selectedIndex
        if(!linkList==""){window.location.href=form.selectThis.options[linkList].value;}
    }
    //--></script>



    and than after the body tag:

    Code

    <?php
    list($dbconn) = pnDBGetConn();
    $pntable =& pnDBGetTables();
       
    $column = &$pntable['users_column'];
    $sql = "SELECT * FROM $pntable[users] ORDER BY pn_uname";
           
    $result =& $dbconn->Execute($sql);

    echo '<form name="dropMenu"><div><select name="selectThis" onChange="goThere(this.form);">
    <option selected value="">   Limoncelli</option>'
    ;                      
    while(!$result->EOF)
    {    
       $name = $result->fields[2];    
       echo '<option value="module=advProfile&uname='.$name'
    ">'
    .$name.'</option>';
       $result->MoveNext();
    }
    echo '</select></div></form>';


    But still doesnt workkkkkkkkk!!!!!!!!

    Can anyone help me out please!!!!!!!!!


    Thanks everyone for the answer submitted!
  • Code

    $dbconn =& pnDBGetConn(true);
    $pntable =& pnDBGetTables();
    $column = &$pntable['users_column'];

    $result = $dbconn->Execute("SELECT $column[uname] FROM $pntable[users] WHERE $column[uname]<>'".pnConfigGetVar('anonymous')."' ORDER BY $column[uname] ASC");

    echo '<form name="uform">
          <select name="umenu" onchange="location.href=uform.umenu.options[selectedIndex].value">'
    ;
          for (; !$result->EOF; $result->MoveNext()) {
          list($uname) = $result->fields;
    echo '<option value="index.php?module=advProfile&uname='.$uname.'">'.$uname.'</option>';
          }
    echo '</select></form>';
  • I see you used a different DB connection type than me, IR actually if I recall properly I think it the method used in pn750 and later? I remember when I made a module I couldn't get this method doesn't work with pn726 , I think...

    -Lobos

    --
    -Lobos
    Professional PHP Framework Services: Concept, Development and Deployment
  • ..right.. you'd just list the $dbconn variable in .726 and below... as you did above :) ..that works with .750+ as well, but there are performance advantages to using the method added in .750.
  • Invalid response thanks a lot it is working now perfectly! I only have one last requirement. How do ai put a first default option? Like "select please"

    Thanks a lot again. ;)
  • hi fracozzo..
    you can add it above the "for" loop:

    Code

    echo '<form name="uform">
          <select name="umenu" onchange="location.href=uform.umenu.options[selectedIndex].value">'
    ;
    echo '<option value="">- Select - </option>';
          for (; !$result->EOF; $result->MoveNext()) {
          list($uname) = $result->fields;
    echo '<option value="index.php?module=advProfile&uname='.$uname.'">'.$uname.'</option>';
         }
    echo '</select></form>';


    ..enjoy :)
  • 0 users

This list is based on users active over the last 60 minutes.