Gossamer Forum
Home : Products : DBMan : Customization :

Links for Todays and yesterdays entries. How?

Quote Reply
Links for Todays and yesterdays entries. How?
Hallo,

I am trying to create classifieds ads from dbman.
I want to create 2 links (like List All): one to list all ads posted today and the other listing all yesterday ads.

Anybody can help me ?

Thanks
Quote Reply
Re: Links for Todays and yesterdays entries. How? In reply to
First of all, look at sub get_date in db.cgi. The first few lines should read:

Code:
my $time = @_;
($time) | | ($time = time());

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);

If your sub get_date doesn't start like that, make it like that.

Before you print out your link (in html_home, probably) add (first closing off any print qq| statement with a |;)

Code:
$today = &get_date;
$days = 2 # actually this is the day before yesterday, but you're going to use "-gt"
$yesterday = &get_date(time() - ($days * 86400));
print qq|<a href="$db_script_link_url&Date=$today">Today's Ads</a>
<a href="$db_script_link_url&Date-gt=$yesterday&Date-lt=$today">Yesterday's ads</a>|;

That should work. However, I've seen some problems with calling the get_date subroutine. As a work-around I had to copy some of get_date into my routine. If the above doesn't work, use this instead:

Code:
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
@now = localtime(time());
($now[3] < 10) and ($now[3] = "0$now[3]");
$now[5] = $now[5]+1900;
$today = "$now[3]-$months[$now[4]]-$now[5]";
@then = localtime(time() - (2*86400));
($then[3] < 10) and ($then[3] = "0$then[3]");
$then[5] = $then[5]+1900;
$yesterday = "$then[3]-$months[$then[4]]-$then[5]";
print qq|<a href="$db_script_link_url&Date=$today">Today's Ads</a>
<a href="$db_script_link_url&Date-gt=$yesterday&Date-lt=$today">Yesterday's ads</a>|;

I know the above routine will work, but it's a little bit longer.


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

All my advice is offered on the basis of kindness-ware. If I've helped you to solve a problem, go out of your way to be kind to someone today.


[This message has been edited by JPDeni (edited March 02, 1999).]
Quote Reply
Re: Links for Todays and yesterdays entries. How? In reply to
JP Deni,

Thanks for your response.

Could you please tell me where to to put the second code?

Thanks
Quote Reply
Re: Links for Todays and yesterdays entries. How? In reply to
Like the first code, put the second in html_home. It seems the logical place to put links for "Today's Ads" and "Yesterday's Ads."

Just be sure not to put it between a

print qq|

and

|;

statement.


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

All my advice is offered on the basis of kindness-ware. If I've helped you to solve a problem, go out of your way to be kind to someone today.

Quote Reply
Re: Links for Todays and yesterdays entries. How? In reply to
JPDeni,

With the changes of code you sent me by email, now the link for today and yesterday entries works very nice.


Thanks
Quote Reply
Re: Links for Todays and yesterdays entries. How? In reply to
To JPDeni. I found this thread most interesting because my application needs to find records where the date is "last week", "last month", etc.

I reviewed your posting and tried to implement your technique. Having gotten past the usual syntax errors of a CGI novice, I got the thing working but it doesn't find any records. I'm sure I'm doing something basic wrong either in where I placed the code in DB.CGI or else in the URL syntax when I call DB.CGI.

The person you helped in this thread indicated you might have sent a further solution by private e-mail, so now I'm not sure your posting is 100%.

Here is the code I added to DB.CGI, and then I'll show you the URL I used.

sub query {
# --------------------------------------------------------
# Added by Sam Gerber to provide for searching fishing reports by date range
my (@months)= qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
# Get date for 8 days ago
@ago8 = localtime(time() - (8*86400));
($ago8[3] < 10) and ($ago8[3] = "0$ago8[3]");
$ago8[5] = $ago8[5]+1900;
$date8ago = "$ago8[3]-$months[$ago8[4]]-$ago8[5]";
# Get date for 31 days ago
@ago31 = localtime(time() - (31*86400));
($ago31[3] < 10) and ($ago31[3] = "0$ago31[3]");
$ago31[5] = $ago31[5]+1900;
$date31ago = "$ago31[3]-$months[$ago31[4]]-$ago31[5]";
# End of code added by Sam Gerber

Here's the URL:

http://fortescue.com/fort-cgi/dbman/db.cgi?db=fishrept&uid=default&view_records=1&sb=2&so=descend&Date-gt=$date31ago

Finally, I did a little debugging and printed the contents of the $date8ago and $date31ago fields on the search_failure form and they are in fact correct.

So ... where did I screw up?

Your assistance is very much appreciated. I wish I could have sent this by email so that other viewers wouldn't be burdened with this.

Thanks much ... Sam (whose CGI skill level is somewhere between pathetic and dangerous)
Quote Reply
Re: Links for Todays and yesterdays entries. How? In reply to
You can't do it the way you've set it up. Move all of your "ago8" and "ago31" definitions to just before you print out the URL. The date has to be defined before it goes to the query subroutine.

The private email that is referred to in previous posts here concerned a bug that has been mentioned elsewhere on the forum. I'll go over it again.

In db.cgi, sub query, look for

Code:
if ($in{"$column-gt"} !~ /^\s*$/) { ($db_sort{$column} eq 'date') and
&date_to_unix($in{"$column-gt"}) or return "Invalid date format: '$in{$column}'");
push(@search_gt_fields, $i); }
if ($in{"$column-lt"} !~ /^\s*$/) { ($db_sort{$column} eq 'date') and
(&date_to_unix($in{"$column-lt"}) or return "Invalid date format: '$in{$column}'");
push(@search_lt_fields, $i); }

Add the characters that are in bold above.




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







[This message has been edited by JPDeni (edited March 24, 1999).]
Quote Reply
Re: Links for Todays and yesterdays entries. How? In reply to
JPDeni: Thank you VERY MUCH for including that fix to the -gt and -lt bug!!! I can't believe I wasted hours on a bug that supports a new feature. Now that the bug is fixed, I can make my call to DB.CGI and supply the date as a LITERAL and the query works.

Regarding my problem as stated in my previous post, I'm afraid I've misled you accidentally and I'm sorry about that.

You see, I don't use html.pl to "print" out the html containing the URL for the user to later click on. Rather, JPD, I wrote my own form external to db.cgi and the URL I showed you contains parameters being passed to DB.CGI.

Consequently I am passing DB.CGI the name of my CGI variable that I want my records' Date field to be compared to. In the absence of documentation and not being very talented with CGI, I thought I could do this. I do understand that the "print" implementation you've explained is done from within the script, making it easy to resolve the variable.

So ... do you have any thoughts on how I can do what I want? My form is asking the user to select records which are for the last 7 days, or last 30 days, and so on. Based on their selection, I want to tell DB.CGI which of my already defined variables it should compare the date to. Is there a way to communicate this way and pass it the name of a variable for it to then resolve and use in the search? I could just as well pass it a value (number of days) from the form, rather than a variable name, but that value would not be associated with a field in my database and therefore I don't know how I could get it to use it in my date calculation.

Could it be that the light I saw at the end of the tunnel is the Amtrak Express?

I hope I've now made this all clear. You're obviously quite skilled with scripting and perhaps you'll see the way. I'm really stuck since I have other date inputs to my searches.

BTW, I went to your web page which is very very tastefully done, both as to its theme and its cosmetics. I tried to find your email address there, since the email icon here in the BBS doesn't work for you. Your web page shows a different name ... is that you?

Sorry for the length of this post ... hope I'll hear from you with some JPDeni "magic".

Regards ... Sam
Quote Reply
Re: Links for Todays and yesterdays entries. How? In reply to
Sam,

First of all, thank you very much for your compliments on my website. Yes, that is me. My name is Carol Hall. JPDeni is a nickname from high school that I decided to use, frankly, so my gender would not be obvious, which I felt might give me a better chance at being taken seriously as a programmer. I think my credentials are pretty well established now, though, so it's safe to let folks in on my little secret. Smile

Now, as to your problem. What I would do is have a field -- probably radio buttons -- with the name "ago" and with the options being 8 or 31. That way, your URL that is sent to the script will include "&ago=8" (or "&ago=31").

In your addition to sub query, use $in{'ago'} as the variable to determine which date to look for. Sticking with the basic format for the routine that you use, it would work like

Code:
if ($in{'ago'}) {
my (@months)= qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
@ago = localtime(time() - ($in{'ago'}*86400));
($ago[3] < 10) and ($ago[3] = "0$ago[3]");
$ago[5] = $ago[5]+1900;
$dateago = ago[3]-$months[$ago[4]]-$ago[5]";
$in{'Date-gt'} = $dateago;
}

I added the "if ($in{'ago'))" part in case not every search will use the feature. Otherwise, you could have some less than satisfactory results.

I hope this works for you. I think I've caught my syntax errors (which I invariably make!), but I haven't tested this.


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





Quote Reply
Re: Links for Todays and yesterdays entries. How? In reply to
JPD, you are BRILLIANT ... in addition to being such a nice person!

Your solution not only works, but it is so graceful and so universal. It will work for all my future date searches. I'm so excited! Just slammed my JavaScript book shut and put it back on the shelf.

Alex is so lucky to have you providing support for his product. If he's reading this, I think he should give you 10% of DBMan revenues! ;-).

I'll get back to you by email to praise you some more and thank you again.

BTW, to bring you down to earth just a tad, the following line had a double syntax error. But that's fine ... I needed to contribute something to this.

$dateago = ago[3]-$months[$ago[4]]-$ago[5]";

Sign me "in your debt" .... Sam
Quote Reply
Re: Links for Todays and yesterdays entries. How? In reply to
 Smile thanks for your kind words. I just love solving puzzle with DBMan. (And it don't hurt to have people tell me how great I am when I do it!! Wink )

I'm not surprised about the syntax error. I make them all the time. If I think about it, when I'm writing things on the list, I run it through Perl to catch them.

I'm really glad it worked for you.


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





Quote Reply
Re: Links for Todays and yesterdays entries. How? In reply to
 
Quote:
The private email that is referred to in previous posts here concerned a bug that has been mentioned elsewhere on the forum.

And I'm ashamed to admit that I hadn't updated the source Frown. I've done so now.

Quote:
Alex is so lucky to have you providing support for his product. If he's reading this, I think he should give you 10% of DBMan revenues! ;-).

Don't I know it! Wink

Cheers,

Alex