[BLOCK] Combobox wi...
 
Notifications
Clear all

[BLOCK] Combobox with categories

6 Posts
2 Users
0 Reactions
2,690 Views
(@wimvincken)
Posts: 44
Eminent Member
Topic starter
 

I've written a block with a combo with categories. The user selects a category and the block follows with displaying the category listing.

I'm beginning to learn writing something in php, so everything is simple.
The problem I'm having is that it does not saves the selected category. I prefer this category in a session variable.

You can download the block block here: http://forum.writingcenter4.info/index.php?action=mgallery;sa=item;id=11335
You can see the block in action here: http://ficdom.net/index.php

The content of the categorycombo is:

<?php
$querystring = "";
if(!defined("_CHARSET")) exit( );

$cookiecatid = $_SESSION['cookiecatid'];

$content = "<select name="categorycombo1" onChange="document.location = ' http://ficdom.net/browse.php?categorychange=1&type=categories&catid=' + this.options[this.selectedIndex].value;">";

$query = dbquery("SELECT * FROM `ficdom_fanfiction_categories` WHERE `parentcatid` = -1 and`numitems`>0 ORDER BY `category`");
while($categories = dbassoc($query))
{
$id = $categories['catid'];
$name = htmlspecialchars($categories['category']);
$itemcount = $categories['numitems'];
$displayname = "".$name." [$itemcount]";
if($id == "$cookiecatid"){
$content .= "<option value=$id selected>$displayname</option>";
}
else{
$content .= "<option value=$id>$displayname</option>";
}
}
$content .= "</select>";
?>

You must add {categorycombo_title} and {categorycombo_content} in your skin after you copied the content of the categorycombo.zip in the block directory of efiction.

As you can see on the session statement

$cookiecatid = $_SESSION['cookiecatid'];

that I tried to save the catid into a session in browse.php, but that did not work very well. It saves the catid correctly, after the block was already loaded.
Ideally, the session would be updated in the block itself:

$content = "<select name="categorycombo1" onChange="document.location = ' http://ficdom.net/browse.php?categorychange=1&type=categories&catid='  + this.options[this.selectedIndex].value;">";

But how to do that, no idea. Can anyone help me with this?


 
Posted : 21/08/2009 10:37 pm
(@lyndsie)
Posts: 1263
Member Moderator
 

I'm a little confused by what you mean, but it looks like its doing what it's supposed to do. I selected Harry Potter and various browse pages only displayed HP universe results. The actual dropdown displayed the Alchemist, though. Not really sure what you're looking for.

My browser is G1 phone's native browser


 
Posted : 22/08/2009 4:51 am
(@wimvincken)
Posts: 44
Eminent Member
Topic starter
 

Thanks, it's okay. I fixed it myself. The source code is updated, it does not change any database.

The site supports multiple categories (like HP, Black Jewels, Narnia and some 50 others).

There must be one combo box, which contains all the top-categories, where the user can select a category from. A category on the Ficdom is being called Universe.

The reason for this combo box is if you click on Categories (especially when you have many of them), then you see this page:
http://ficdom.net/browse.php?type=categories

And with Ficdom.net, there are descriptions for each (top) category and that is much too much. Many users have asked if it is possible to have a short-cut, and here it is, the shortcut in the form of a combo.

But there is more. With the session variable, which holds the active catid, I can enhance the Most Recent fic to display only those fics, which are most recent in the selected category. The same for Featured Stories.


 
Posted : 22/08/2009 5:15 am
(@wimvincken)
Posts: 44
Eminent Member
Topic starter
 

Someone knows how to get all categories in the combo, but a tree form:

i.e.
Category 1
--Category 1A
--Category 1B
----Category 1B.1
Category 2
--Category 2A
----Category 2A.1
----Category 2A.2


 
Posted : 24/08/2009 11:10 am
(@wimvincken)
Posts: 44
Eminent Member
Topic starter
 

Because of this block, I also add the blocks for Most Recent and Featured Stories

The only change I'm going to make is that it displays the Most Recent and Featured Stories stories within the chosen or active category.


 
Posted : 30/08/2009 11:31 pm
(@wimvincken)
Posts: 44
Eminent Member
Topic starter
 

A version update (version 2.1), which includes only a bug fix.
http://forum.writingcenter4.info/index.php?action=mgallery;sa=item;id=11724


 
Posted : 01/09/2009 5:22 am
Share: