Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1
    Casual Pligger kanedaguy's Avatar
    Joined
    Feb 2007
    Posts
    70
    Thanks
    Received:0
    Given: 0

    Drop Down List with Alphabetical list of Stories

    Hello Forum Gods

    Do you think this is possible to be done?
    Create a drop down list enumerated with the list of stories in the system (sorted alphabetically).

    Thank you.

  2. #2
    Constant Pligger savant's Avatar
    Joined
    Apr 2006
    Posts
    1,181
    Thanks
    Received:0
    Given: 0
    yes this can be done.

  3. #3
    Casual Pligger kanedaguy's Avatar
    Joined
    Feb 2007
    Posts
    70
    Thanks
    Received:0
    Given: 0


    Ok, and can you help me? Or if its on some tutorial site, guide me?

  4. #4
    Constant Pligger savant's Avatar
    Joined
    Apr 2006
    Posts
    1,181
    Thanks
    Received:0
    Given: 0
    you can do a simple sql query to get the data

    select * from pligg_links order by links_title ASC;

    and then get the link_title and populate a drop down box.

    references:
    http://dev.mysql.com/doc/refman/5.0/en/select.html
    http://www.freewebmasterhelp.com/tutorials/phpmysql
    http://www.plus2net.com/php_tutorial..._down_list.php

  5. #5
    Casual Pligger kanedaguy's Avatar
    Joined
    Feb 2007
    Posts
    70
    Thanks
    Received:0
    Given: 0
    this is a bit lame, but could you possibly post some example code?

  6. #6
    Constant Pligger savant's Avatar
    Joined
    Apr 2006
    Posts
    1,181
    Thanks
    Received:0
    Given: 0
    ok here's some code.

    This was put inside the do_sidebar function in htm1.php

    PHP Code:
            //this gets all the stories
        
    $storySql "SELECT link_id, link_title from " table_links " where link_status = 'published' or link_status = 'queued';";
        
    $stories $db->get_results($storySql);
        
    //store the id and title in an array
        
    $storylist = array();
        foreach ( 
    $stories as $story )
            
    $storylist[] = array($story->link_id,$story->link_title);
        
    //pass the array to the template
        
    $var_smarty->assign('dropdownStories',$storylist); 
    If you are putting it somewhere else it can be $main_smarty or $smarty.

    And this bit puts the items in a drop down box.
    I put this in sidebar.tpl

    PHP Code:
    <li>
        <
    div class="box" id="dropdownstory">
            <
    select>
                {foreach 
    from=$dropdownStories value=dropdownstory}
                <
    option value="{$dropdownstory[0]}">{$dropdownstory[1]}</option>
                {/foreach}
            </
    select>
        </
    div>
    </
    li

  7. #7
    Casual Pligger kanedaguy's Avatar
    Joined
    Feb 2007
    Posts
    70
    Thanks
    Received:0
    Given: 0
    wow this is great!!!

    Thank you.

    Now I have to get it sorted alphabetically and include links so when somebody chooses a movie it loads that page.

  8. #8
    Casual Pligger kanedaguy's Avatar
    Joined
    Feb 2007
    Posts
    70
    Thanks
    Received:0
    Given: 0
    PHP Code:
    //this gets all the stories
        
    $storySql "SELECT link_id, link_title from " table_links " where link_status = 'published' or link_status = 'queued' ORDER BY link_title ASC;";
        
    $stories $db->get_results($storySql);
        
    //store the id and title in an array
        
    $storylist = array();
        
    $storylist[] = array(0"Select your story");
        foreach ( 
    $stories as $story )
            
    $storylist[] = array($story->link_id,$story->link_title);
        
    //pass the array to the template
        
    $var_smarty->assign('dropdownStories',$storylist); 
    Hello
    Thank you for that.

    I got the title of the drop-down list (Select your story), and I got the list sorted.

    But I am trying to make it so that when the user selects the story, the page goes to that link.

    Grateful for any pointers.

    Thank you.

  9. #9
    Casual Pligger kanedaguy's Avatar
    Joined
    Feb 2007
    Posts
    70
    Thanks
    Received:0
    Given: 0
    Hello,
    This is what I came up with another guy on some web forum.
    On the template side, I want to make it so that when the person chooses the story, the page reloads with that link.

    Any ideas please?
    Thank you.

    PHP Code:
    if (isset($_GET['dropdownStories']))
    {
        
    $id = (int) $_GET['dropdownStories'];
        
    $query "SELECT link_url FROM " table_links " WHERE link_id = $id";
        
    $result mysql_query($query) or die(mysql_error());
        if (
    mysql_num_rows($result))
        {
            list(
    $link_url) = mysql_fetch_array($result);
            
    header ('Location: '.$link_url);
            exit();
        }
        else
        {
            echo 
    'invalid selection. Try again';
        }   
    }

    //this gets all the stories
        
    $storySql "SELECT link_id, link_title from " table_links " where link_status = 'published' or link_status = 'queued' ORDER BY link_title ASC;";
        
    $stories $db->get_results($storySql);
        
    //store the id and title in an array
        
    $storylist = array();
        
    $storylist[] = array(0"Select your story");
        foreach ( 
    $stories as $story )
            
    $storylist[] = array($story->link_id,$story->link_title);
        
    //pass the array to the template
        
    $var_smarty->assign('dropdownStories',$storylist); 

  10. #10
    Constant Pligger savant's Avatar
    Joined
    Apr 2006
    Posts
    1,181
    Thanks
    Received:0
    Given: 0
    I'm not sure of the list. because there only should be one link with one id.


    PHP Code:
    if (mysql_num_rows($result))
        {
            
    $row mysql_fetch_assoc($result);
            
    $link_url $row['link_url'];
            
    header ('Location: '.$link_url);
            exit();
        } 

Page 1 of 2 12 LastLast

Similar Threads

  1. template page drop list won't populate
    By greeneyed_itgirl in forum Questions & Comments
    Replies: 1
    Last Post: 02-11-2009, 05:31 AM
  2. [Fixed] cann't list friends list in the yget templates
    By haxhax in forum Questions & Comments
    Replies: 5
    Last Post: 02-11-2007, 11:44 AM
  3. Category List: Alphabetical order only?
    By revolver in forum Questions & Comments
    Replies: 3
    Last Post: 11-07-2006, 09:17 AM
  4. Where to activate the drop-down problem option list?
    By NeverHome in forum Questions & Comments
    Replies: 1
    Last Post: 06-16-2006, 03:41 AM
  5. Anyone actually using Report a problem drop list?
    By can8dn in forum Questions & Comments
    Replies: 1
    Last Post: 05-22-2006, 11:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Pligg Modules and Pligg Templates from Pligg Pro Web Hosting Services by Midphase Dreamhost Web Hosting Donate to Pligg