Gossamer Forum
Home : Products : DBMan : Installation :

Classifieds

(Page 1 of 2)
> >
Quote Reply
Classifieds
Hi,

I had somebody ask me about making them a Classified Ads site. A user would be able to Add, Modify, Delete ads. This would be free for the user at the time being. In order for the user to add an ad they would first have to log in and create an account, and then add the record with their account.

I think this would be a good idea to make this in Dbman. There is one problem though. How can I have all the categories list in the Homepage, once they would click on the category, they would get to all the sub categories, and then they would see all the ads for that sub category (kind of like Yahoo Classifieds).

I would really like to use Dbman for this, since that's what I've been learning for the last three months, but the category listing is my only problem/concern. Please tell me what you suggest for me to use. Would you recommend Links to do this?

Thank You
Eli
Quote Reply
Re: Classifieds In reply to
Eli,

Yes, I would think that Links would be a better option for something like this. If you only had one "layer" of categories it might be ok, but if you need subcategories, it would probably be best to use Links. I've been meaning to have a go off modifying Links for something like this for a long time, but I've never gotten around to it. But no doubt someone in the Links forum has had a go.

Good luck with it anyway...

adam
Quote Reply
Re: Classifieds In reply to
Hi Eli!

We wanted a similar approach on our site. We used DBman for the database and JPDeni's Short Display mod to list everything by category. Then we built an HTML page on our site that has specific categories built into the referring URLs.

Drop by and take a look. Maybe this solution will work as well for you as it seems to for us.

http://www.IDunno4Recipes.com/RecipeArchives.htm


------------------
BigBritchs
BigBritchs@IDunno4Recipes.com



[This message has been edited by BigBritchs (edited June 24, 1999).]
Quote Reply
Re: Classifieds In reply to
Eli, I know you have wanted this for a long time and I didn't know how to give it to you. I finally figured it out. (It really helps to have a few homemade Snickerdoodles to get the brain working! A great big public thank you to BigBritchs!! Smile )

Okay. Here's whatcha do.

You will need a field called "Category" and another field called "Subcategory." Both should be required fields.

In your link to list out the categories, use

<a href="$db_script_link_url&list_categories=1">List Categories</a>

The mod below will only list categories that are currently in the database and and subcategories that are currently within the selected category.

In db.cgi, sub main, somewhere in the midst of the other "elsif" statements, add

Code:
elsif ($in{'list_categories'}) { if ($per_view) { &html_list_categories; } else { &html_unauth; } }

Then add the following subroutine to the html.pl file. It is set up to work with my user-friendly html.pl file or my short/long display mod, but you might be able to figure out how to make it work with the "out of the box" html.pl file.

Code:
sub html_list_categories {
# --------------------------------------------------------

for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Category" ) {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierror("No Category field defined");
}

if ($in{'Category'}) {
$page_title = "$in{'Category'} sub-category listing";
&html_page_top;
$found = 0;
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Subcategory" ) {
$fieldnum2 = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierror("No Subcategory field defined");
}
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if ($fields[$fieldnum] eq $in{'Category'}) {
if (!(grep $_ eq $fields[$fieldnum2], @selectfields)) {
push (@selectfields, $fields[$fieldnum2]);
}
}
}
close DB;
foreach $field (sort @selectfields) {
$sfield = &urlencode($field};
print qq|<$font><a href="$db_script_link_url&Category=$in{'Category'}
&Subcategory=$sfield&view_records=1">$field</a></font><BR>|;
}
}

else {
$page_title = "Category Listing";
&html_page_top;

open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
}
close DB;

foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&list_categories=1&Category=$sfield">$field</a></font><BR>|;
}
}

&html_footer;
&html_page_bottom;

}

Also, you will need to add a subroutine to db.cgi

Code:
sub urlencode {
# --------------------------------------------------------
my($toencode) = @_;
$toencode=~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$toencode=~s/\%2F/\//g;
return $toencode;
}

Now you say that you want the Categories to list on the home page. Okay. Put this in sub html_home:

Code:
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Category" ) {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierror("No Category field defined");
}
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
}
close DB;

foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&list_categories=1&Category=$sfield">$field</a></font><BR>|;
}

------------------
JPD







[This message has been edited by JPDeni (edited June 24, 1999).]

[This message has been edited by JPDeni (edited June 29, 1999).]
Quote Reply
Re: Classifieds In reply to
JP, your a doll. Everything works, BUT ... I only get 1 category out of 15 and, I only get 1 subcategory out of 30.

I also have some other questions.

"You will need a field called "Category" and another field called "Subcategory." Both should be required fields. "

dahh, this is really dumb but, what kind of categories are these? radio/select/check box/text ???? Frown

"In your link to list out the categories, use
<a href="$db_script_link_url&list_categories=1">List Categories</a>"

Could this "=1" be my problem or is more related to defining the field type -- I tried select fields but ....

Beyond my ignorance the code works like a dream even with ONLY 1 category and ONLY 1 subcategory working.

Please help.

jdunes
Quote Reply
Re: Classifieds In reply to
 
Quote:
Everything works, BUT ... I only get 1 category out of 15 and, I only get 1 subcategory out of 30.

Then it doesn't work! Smile Unless you only have one record in your database. Then it's working just as it should.

I guess I'd need to see your code and have access to your database to know why.

Quote:
what kind of categories are these?

Whatever you want them to be. It doesn't matter, so long as there is something in that field in every record. The code above doesn't care about the type of input field you use. It just looks at the values.

Quote:
Could this "=1" be my problem or is more related to defining the field type -- I tried select fields but
....

The "list_categories=1" part of the link is a command that is being sent to the db.cgi script so it knows which subroutine to go to. It has nothing to do with the field type.

This is what the code does:
If no category has been defined previously, it looks through each record and finds the value of the category field. If that value is not already in the category array, it sticks it in there. Once the script has gone through all the records, it prints out the categories, with a link to get a list of the subcategories that match each of the categories.

If a category was defined previously -- the user came from the category list -- the script again goes through each record in the database and looks for the category that was defined. If it finds that category, it then pulls the value of the subcategory out of the record and sticks it into an array. After it's gone through all the records, it prints out the subcategories, with links to do a search for the records that match both the category and the subcategory.

Is that clearer?

------------------
JPD





Quote Reply
Re: Classifieds In reply to
Jee, and I was hoping that I didn't have put you through all this trouble, sorry JP ...

Here's where the running script is:
http://www2.comco.ne.jp/~hakuja/cgi-bin/dbman/db.cgi?db=default&uid=default

the text files are at:
http://www2.comco.ne.jp/~hakuja/dbman/db.txt
http://www2.comco.ne.jp/~hakuja/dbman/default.txt
http://www2.comco.ne.jp/~hakuja/dbman/html.txt

to see the script running in action you might have to set your browser's character set to Japanese.

Thanks for all your help.

jdunes
Quote Reply
Re: Classifieds In reply to
It wouldn't matter if I did set it to read Japanese. I can't read Japanese anyway. Smile

What are the "Categories" and "subcategories" of the records in your database? Are they all the same? When I click on the one subcategory, I get the same 4 records that I got when I did a "List All." And when I selected the first option in the first select field that showed up (the first one says that there isn't a select field for "Toyota"), I got the same 4 records. When I selected the other options, I got "no matching records." If that select field matches "Category" or "Subcategory," then you should only get one listing.

I did notice something, though, that I forgot before. There might be spaces in the Category and Subcategory values.

You need to add another subroutine, one that I stole from Links:

Code:
sub urlencode {
# --------------------------------------------------------
my($toencode) = @_;
$toencode=~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$toencode=~s/\%2F/\//g;
return $toencode;
}

Then make the following adjustments to the code. (I'll make the changes as soon as I finish this so it will all be together.)

Code:
foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&Category=$in{'Category'}
&Subcategory=$sfield&view_records=1">$field</a></font><BR>|;
}

and

Code:
foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&list_categories=1
&Category=$sfield">$field</a></font><BR>|;
}



------------------
JPD







[This message has been edited by JPDeni (edited June 29, 1999).]

[This message has been edited by JPDeni (edited July 10, 1999).]
Quote Reply
Re: Classifieds In reply to
Hey thanks for the quick reply.

In my config file there should be no spaces since they are all single Japanese words. But you did mention that if the Category and Subcategory match the same record you will get only 1 listing .... hehehehe Ummm, that's probably the problem since all the fields are test ones set to Toyota MR2s. bummmer, Is there a way to show all the possible listings not just the available listings. for example, to be able to show all the models from Toyota even though there are only listings for MR2s? Before I go public with this I want to look as much as professional as possible -- well I gotta a long way to go on that side but at least for the database.
Quote Reply
Re: Classifieds In reply to
I would add some more test records that have different categories and subcategories.

It is possible to make it list all the available categories -- but not subcategories. Unless you have a listing somewhere of the subcategories that go with each category.

Besides, I find if I go to a site and it says that I can search for something, I'd like to have that something actually exist. I think it looks unprofessional to, for example, have a link where I can click on "Mazda" and then have it say "No matching records." I'd rather know up front that there aren't any Mazdas so I don't get my hopes up. But that's just me. Smile


------------------
JPD





Quote Reply
Re: Classifieds In reply to
JP, you're teasing me Smile

Yeah, you're right I really shouldn't provide subcategories that don't have actual data for them, but just for curiosty's sake how would I get all the categories to show? I need to find a balance between -- not looking to rinky dink and not having empty information.

I'm also going to increase the amount of test data but first I have to rebuild my config file since I hacked it to get this mod running first.

" And when I selected the first option in the first select field that showed up (the first one says that there isn't a select field for "Toyota"), I got the same 4 records. When I selected the other options, I got "no matching records."

I got a question: what did you mean by "I selected the other options, I got "no matching records."?

the selectfield is my fault since I hacked the default.cfg but I when I checked by database I didn't get other options just Toyota in Japanese for Category and then MR2 for subcategory. hmmm,

anyway, thanks a whole bunch.

jdunes

[This message has been edited by jdunes (edited June 29, 1999).]
Quote Reply
Re: Classifieds In reply to
Thanks Jp for helping to get moving again. I've been sitting on dbman for a couple of months since I wasn't sure how I wanted to do this -- and out of the blue the solution came (classified views).

Nah, we can't know everything about everything. See without you I wouldn't know anything about Perl (which I still don't Smile ).

I meant that I hacked the config file not your code since I be in deeper sh_t before I knew it. although, I've been getting along with cutting and pasteing ALL YOUR GREAT MODS.

I'll try to figure out where to put everything tonite if I don't pass out from exhaustion first.

THANKS JP

jdunes
Quote Reply
Re: Classifieds In reply to
What I meant when I wrote
Code:
foreach $field (sort @selectfields) {
$sfield = &urlencode($field};
print qq|<$font><a href="$db_script_link_url&Category=$in{'Category'}
&Subcategory=$sfield&view_records=1">$field</a></font><BR>|;
}

to

Code:
foreach $i ( 0 .. $#{$db_models{$in{'Category'}}}){
$here = 0;
foreach $field (@selectfields) {
if ($db_models{$in{'Category'}}[$i] eq $field) {
$here = 1;
last;
}
}
if ($here) {
$sfield = &urlencode($field);
$scat = &urlencode($in{'Category'});
print qq|<$font><a href="$db_script_link_url&Category=$scat
&Subcategory=$sfield&view_records=1">$field</a></font><BR>|;
}
else {
print "$db_models{$in{'Category'}}[$i]<BR>";
}
}

In the second part, the part that prints out the Category list, instead of

Code:
foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&list_categories=1&Category=$sfield">$field</a></font><BR>|;
}

use

Code:
@cats = split (/\,/, $db_select_fields{'Make'});
foreach $cat (@cats) {
$here=0;
foreach $field (sort @selectfields) {
if ($cat eq $field) {
$here=1;
last;
}
}
if ($here) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&list_categories=1&Category=$sfield">$field</a></font><BR>|;
}
else {
print "$cat<BR>";
}
}

(In the midst of this I realized I need to urlencode the $in{'Category'} variable too, in the subcategory listing.)

I think this will work. I did test it for syntax errors, but that's all.

------------------
JPD





Quote Reply
Re: Classifieds In reply to
Hey JP,

Bad news, I went into the html.pl and changed the goodies to include the space reduction sub that you created and then add the new mod that you did for me and everything crashed. Frown I wonder if this be because my data is in Japanese? here's the error.

CGI ERROR
==========================================
Error Message : Error loading required libraries.
Check that they exist, permissions are set correctly and that they compile.
Reason: syntax error at /home2/hakuja/.//public_html/cgi-bin/dbman/html.pl line 555, near "$urlencode("

typical debugger, actually the code lines should be somewhere near 655-700.

also, the important files are still in here:

Here's where the running script is:
http://www2.comco.ne.jp/~hakuja/cgi-bin/dbman/db.cgi?db=default&uid=default

the text files are at:
http://www2.comco.ne.jp/~hakuja/dbman/db.txt
http://www2.comco.ne.jp/~hakuja/dbman/default.txt
http://www2.comco.ne.jp/~hakuja/dbman/html.txt

Sorry to bother you again.
Quote Reply
Re: Classifieds In reply to
Your problem is exactly on line 555.

You have

Code:
$sfield = $urlencode($field);

It needs to be

Code:
$sfield = &urlencode($field);

My fault. I made the error in my previous code. I'll fix it right now.


------------------
JPD





Quote Reply
Re: Classifieds In reply to
 Smile cut and paste does work sometimes and I was beginning to think that I was using double quotes instead of 2 single quotes again.

Thanks a million JP.
Quote Reply
Re: Classifieds In reply to
JP, help I screwed up somewhere and I can't for the life of me figure out I did wrong. The script is running but I lost your wonderful mod. Frown Blue is the word for today.

Here is the areas I tinckered with. I must of missed something that you took time to write out for me. Sorry Frown

sub html_list_categories {
# --------------------------------------------------------
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Maker" ) {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierror("No Maker field defined");
}
if ($in{'Maker'}) {
$page_title = "$in{'Maker'} sub-category listing";
&html_page_top;
$found = 0;
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Model" ) {
$fieldnum2 = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierror("No Model field defined");
}
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if ($fields[$fieldnum] eq $in{'Maker'}) {
if (!(grep $_ eq $fields[$fieldnum2], @selectfields)) {
push (@selectfields, $fields[$fieldnum2]);
}
}
}
close DB;
foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&Maker=$in{'Maker'}&Model=$field&view_records=1">$field</a></font><BR>|;
}
}
else {
$page_title = "Maker Listing";
&html_page_top;
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
}
close DB;

foreach $i ( 0 .. $#{$db_models{$in{'Maker'}}}){
$here = 0;
foreach $field (@selectfields) {
if ($db_models{$in{'Maker'}}[$i] eq $field) {
$here = 1;
last;
}
}
if ($here) {
$sfield = &urlencode($field);
$scat = &urlencode($in{'Maker'});
print qq|<$font><a href="$db_script_link_url&Maker=$scat&Models=$sfield&view_records=1">$field</a></font><BR>|;
}
else {
print "$db_models{$in{'Maker'}}[$i]<BR>";
}
}
}
&html_footer;
&html_page_bottom;
}

##########################################################
## Home Page ##
##########################################################

sub html_home {
# --------------------------------------------------------
# The database manager home page.

&html_page_top("Main Menu");

for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Maker" ) {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierror("No Maker field defined");
}
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
}
close DB;

@cats = split (/\,/, $db_select_fields{'Make'});
foreach $cat (@cats) {
$here=0;
foreach $field (sort @selectfields) {
if ($cat eq $field) {
$here=1;
last;
}
}
if ($here) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&list_categories=1&Maker=$sfield">$field</a></font><BR>|;
}
else {
print "$cat<BR>";
}
}


# <--- Start of page text --->
Quote Reply
Re: Classifieds In reply to
What do you mean you "lost it"? What is it doing, or not doing? What am I looking for?


------------------
JPD





Quote Reply
Re: Classifieds In reply to
Sorry, Jp for not being more informative.

What I meant by when I said I lost it, means that I no longer get any type of links to be followed even though I have data in the database. Before you were able to click on the link and it would show you the records. Well, I don't get the blue links anymore. sort of strange. also I was wondering if I incorporated your mod properly. there must be something I'm missing. Until, now whenever you had helped me I figured it out but this time I'm totally lost.

thanks
Quote Reply
Re: Classifieds In reply to
You mean nothing is printing out? Or that you get a list of the categories with no links?

I'm not sure why you have the code in both the "list categories" and "home" subroutines.

You may need to start over from scratch, though. Sometimes that's the only way to do it. I don't see the problem.


------------------
JPD





Quote Reply
Re: Classifieds In reply to
Out of all of this effort, did you guys come up with a finalized Category Mod? I could use one in a big way, even if its only 2 levels deep.
Quote Reply
Re: Classifieds In reply to
katana Man,

Umm, I tried but somewhere I got lost along the way, I don't know perl -- I can only follow other peoples instructions. I did get part of it running but then I screwed it up again. I think I went wrong somewhere with my default.cfg. But you know a hell of a lot more than I do, maybe you might get this thing working. Forget the code that I posted here -- it's wrong. try using only JP's instructions I think it's all workable. Sorry Frown
Quote Reply
Re: Classifieds In reply to
So what's the status now? Katana Man, do you still need this? jdunes, did you get it worked out?


------------------
JPD





Quote Reply
Re: Classifieds In reply to
I tried installing this mod into my Classified Ad program. It is not working that well. I am able to get a listing of categories. However, when I click on a category, I get the following error message:

Code:
CGI ERROR
==========================================
Error Message : fatal error: Undefined subroutine &main::cgierror called at /mnt/web/guide/anthrotech/cgibin/classifieds/ads/html.pl line 414, chunk 4.

Script Location : /mnt/web/guide/anthrotech/cgibin/classifieds/ads/index.cgi
Perl Version : 5.00404
Setup File : default.cfg
User ID : default
Session ID : default

Form Variables
-------------------------------------------
Category : Business
db : default
list_categories : 1
uid : default

I know that the problem could be attributed to the lack of "sub-categories". How do I create a simple category listing that will only include "Category" with no sub-categories? Also what are the codes to add number of records next to each category. I am using more complex codes in another database program. But it would be nice to install this mod and have it work with numbers of records added to each Category.

To see an example, go to:

http://anthrotech.com/...ult&browse_cat=1

TIA.

Smile

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Classifieds In reply to
This thread is already pretty long. Why don't you start a new one, Eliot, and post the code you're using and exactly what you want to do.


------------------
JPD





> >