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.


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
ok here's some code.
This was put inside the do_sidebar function in htm1.php
If you are putting it somewhere else it can be $main_smarty or $smarty.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);
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>
HelloPHP 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);
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.
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);