Gossamer Forum
Home : Products : DBMan : Customization :

Most recent

(Page 1 of 2)
> >
Quote Reply
Most recent
I suppose it is possible to add a bit of code to the dbman to make it possible to see some # of the most recent records. i.e. to see 10 (or 12 or 15 etc) most recent records or to see records added 10 (or 14 or 21 etc) days ago. I even suppose somebody had done it already. Please, help me with this small enhancement.
Quote Reply
Re: Most recent In reply to
Which do you want? The most recent x number of records or the ones added in the past x number of days?


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





Quote Reply
Re: Most recent In reply to
Sure I need both (or at least either Wink)
Quote Reply
Re: Most recent In reply to
I made a "what's new in the past x days" sort of mod, which you can pick up at http://www.jpdeni.com/dbman/whatsnew.txt

There was an error in it, but I fixed it today.

The "past x number of records" mod depends a lot on how your database is set up. Do you have a numeric ID key for each record?





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





Quote Reply
Re: Most recent In reply to
Yes, there is an ID.
And why not to make it based not on ID but again on the date field?
Thanks for the Whatsnew thingi - I'll go and check it out right now.
Quote Reply
Re: Most recent In reply to
You can make it based on the Date if you want.

You can have a link that is

<a href="$db_script_link_url&$db_key=*&mh=10&sb=4&so=descend&view_records=1">
Last 10 records added</a>

Change the &mh=10 to the number of records you want to show and change &sb=4 to match the field number of your date field.

The only thing you might not want is that you will get a list of the "previous and next" records at the top of your page, too. If you don't want that, we can work out a way around it.


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





Quote Reply
Re: Most recent In reply to
Thanks again for your care.
I did not have enough time to implement (try) your modifications yet. I only looked through the code. Actually, what I had in mind was slightly different from this. I thought of including most recent as a search item within a search form. Something like select box of the kind of
"show last 10(15,20 etc) records"
or
"show records added in the last 10 (15,20 etc) days"
However what you propose is good too
As soon as I'll have time I'll try to make it both ways Wink
Thanks again
Cheers
Quote Reply
Re: Most recent In reply to
Oh, okay. You can do that, too.

Name your "show records added in the last 10 (15,20 etc) days" select field whats_new_days. (I'm doing this one first because it's easier. Maybe I'll figure out the other one by the time I'm finished with this. Smile)

In db.cgi, sub query, after

local (%sortby);

add

Code:
if ($in{'whats_new_days'}) {
$in{'Date-gt'} = &get_date(time() - (($in{'whats_new_days'}+1) * 86400));
}

You will still have to make the adjustments to sub get_date and sub query that are listed in the "What's New" mod.

Also, if the field that holds the date the record was added is not "Date," change the $in{'Date-gt'} accordingly.

Okay. The last x number of records added. The only way to do it is to use the numerical key. Using the date will not necessarily give you the last x number of records.

For example, let's say this number of records were added on the following days:

the 20th -- 5 records
the 22nd -- 3 records
the 25th -- 4 records

If we looked for records added after the 19th, and we wanted just the last 10 records, we would get 12 records instead. In order to get only the records added on the 22nd, the 25th and the last three added on the 20th, we have to use the numeric key.

However, since there could be deletions in the meantime, we can't look at the .count file and subtract 10 from that number. What we have to do instead is find out how many records there are in the database, find the value of the key for the record that is (x+1) from the end and search for the key values that are greater than the value of that record.

It seems odd to get all the data once and then have to look for it again, but that's the only way I know of to make things like the sorts and other things work.

Name your "show last 10(15,20 etc) records" select field whats_new_records.

Just below the code you added above, add

Code:
if ($in{'whats_new_records'}) {
open (DB, "<$db_file_name") or &cgierr("error in search.
unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
$number_of_records = scalar(@lines);
$target_record = $lines[$number_of_records - ($in{'whats_new_records'} + 1)];
@data = &split_decode($target_record);
$in{"$db_key-gt"} = $data[$db_key_pos];
}



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







[This message has been edited by JPDeni (edited July 01, 1999).]
Quote Reply
Re: Most recent In reply to
You are so quick, I can't really catch up with you. I'm always a day behind. Today I sorted things out with the previous bit of code (thanks again) and came up with the following question. It all worked just fine but when I tried to make it work from the address line of a browser it obviously did not work because of $date. I sort of need this feature to refer to the database from a static html. What do you think, is there a way to do this? (I'm not a programer myself therefore I ask ;().
CU
Quote Reply
Re: Most recent In reply to
I think if you use the code I gave you here, it will work just fine on your static html page.


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





Quote Reply
Re: Most recent In reply to
I did not quite understand where to add the second bit of the code. And, just to make sure all this is an addition to the standard whatsnew mode, is it? It cannot work without whatsnew.
Quote Reply
Re: Most recent In reply to
Don't worry about the "What's New" mod you got from my site. This is all you need.

Make sure that your $db_key is set to a counter-type field. Make sure you have a field called Date which holds the date the record was added -- it has &get_date as its default value.

Open up db.cgi. Look for sub get_date {. Copy the the following over the subroutine in your script.

Code:
sub get_date {
# --------------------------------------------------------
# Returns the date in the format "dd-mmm-yyyy".
# Warning: If you change the default format, you must also modify the &date_to_unix
# subroutine below which converts your date format into a unix time in seconds for sorting
# purposes.
my ($time) = $_[0];
($time) or ($time = time());

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;

return "$day-$months[$mon]-$year";
}

Then look for sub query, also in the db.cgi file. Paste the following through the line--

# If we don't have anything to search on, let's complain

Code:
sub query {
# --------------------------------------------------------
# First let's get a list of database fields we want to search on and
# store it in @search_fields

my ($i, $column, @search_fields, @search_gt_fields, @search_lt_fields, $maxhits, $numhits, $nh,
$field, @regexp, $line, @values, $key_match, @hits, @sortedhits, $next_url, $next_hit, $prev_hit,
$first, $last, $upper, $lower, $left, $right, $restricted);

local (%sortby);

if ($in{'whats_new_days'}) {
$in{'Date-gt'} = &get_date(time() - (($in{'whats_new_days'}+1) * 86400));
}

if ($in{'whats_new_records'}) {
open (DB, "<$db_file_name") or &cgierr("error in search.
unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
$number_of_records = scalar(@lines);
$target_record = $lines[$number_of_records - ($in{'whats_new_records'} + 1)];
@data = &split_decode($target_record);
$in{"$db_key-gt"} = $data[$db_key_pos];
}

# First thing we do is find out what we are searching for. We build a list of fields
# we want to search on in @search_fields.
if ($in{'keyword'}) { # If this is a keyword search, we are searching the same
$i = 0; # thing in all fields. Make sure "match any" option is
$in{'ma'} = "on"; # on, otherwise this will almost always fail.
foreach $column (@db_cols) {
if (($db_sort{$column} eq 'date') or &date_to_unix($in{'keyword'})) { $i++; next; }
if ($i == $auth_user_field) { $i++; next; }
push (@search_fields, $i); # Search every column
$in{$column} = $in{'keyword'}; # Fill %in with keyword we are looking for.
$i++;
}
}
else { # Otherwise this is a regular search, and we only want records
$i = 0; # that match everything the user specified for.
foreach $column (@db_cols) {
if ($in{$column} =~ /^\>(.+)$/) { ($db_sort{$column} eq 'date') and (&date_to_unix($1) or
return "Invalid date format: '$1'");
push (@search_gt_fields, $i); $in{"$column-gt"} = $1; $i++; next; }
if ($in{$column} =~ /^\<(.+)$/) { ($db_sort{$column} eq 'date') and (&date_to_unix($1) or
return "Invalid date format: '$1'");
push (@search_lt_fields, $i); $in{"$column-lt"} = $1; $i++; next; }
if ($in{$column} !~ /^\s*$/) { ($db_sort{$column} eq 'date') and (&date_to_unix($in{$column}) or
return "Invalid date format: '$in{$column}'");
push(@search_fields, $i); $i++; next; }
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); }
$i++;
}
}
# If we don't have anything to search on, let's complain.

On your form on your static html page, include the following select fields:

Code:
<select name="whats_new_days">
<option>---
<option>10
<option>12
<option>15
<option>20
</select>
 
<select name="whats_new_records">
<option>---
<option>10
<option>15
<option>20
<option>25
</select>



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







[This message has been edited by JPDeni (edited July 03, 1999).]
Quote Reply
Re: Most recent In reply to
again I'am a day beyound. Yesterday I made the code you've posted working. It works just fine. I'll immediately try this. Just to make sure - we take sort of "clean" db.cgi and *html.pl with no addition at all, we add your last post and we get both types of searches I wanted?
It's really perfect. Thanks a lot.
Quote Reply
Re: Most recent In reply to
Thank You
It works!!!
However, not perfectly. When I use &mh=20&whats_new_records=20 I expect to have just one page with 20 records on it. Instead it gives 16 records in one database and about 200 in the other.
It is probably because I've a lot of records of the same date several month ago.
Is there a way around it?
But thank you again anyway
Quote Reply
Re: Most recent In reply to
I'm glad it works! Smile

I don't know of a way around the problem you're having, though. Sorry.


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





Quote Reply
Re: Most recent In reply to
Look, here I am again Smile
There seems to be another bug in this mod.
I just looked in my logs and found that after I've implemented this mod all IPs disappeared and is places incorrect (but always the same) date. on the server (unix hypermart) it looks like
user logged on at 20:51:56 on 31-Dec-1969 from
user logged on at 20:52:45 on 31-Dec-1969 from
user logged on at 04:46:19 on 31-Dec-1969 from

on my comp (NT Apache) it looks
user logged on at 21:57:33 on 01-Jan-1970 from
user logged on at 22:06:35 on 01-Jan-1970 from
koka logged on at 22:42:53 on 01-Jan-1970 from
user logged on at 02:44:16 on 01-Jan-1970 from
So it still gets the time and there is a funny one day difference between U and NT (i have several databases and all logs look the same no matter what date it really is)
What's going on?????
Quote Reply
Re: Most recent In reply to
I am having a similar problem on our NT server. Dates are coming out like you've posted. It'd be nice to fix this bug.

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: Most recent In reply to
I don't know for sure what the problem is. You might try this, though.

In auth.pl, sub auth_logging, change

my ($date) = &get_date;

to

my ($date) = &get_date();

Let me know what happens.


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





Quote Reply
Re: Most recent In reply to
Ariadna, is this the code you were talking about in the other forum? Can we switch the discussion to here so I can have the code available to look at?

I just thought of another possible fix for the problem you're having with the log file. Go into sub get_date and change every reference to $time to $time1. I think there may be a conflict with another variable called $time.


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





Quote Reply
Re: Most recent In reply to
JPDeni,

I have added the codes into the sub query sub-routine (and I did replace the get_date sub-routine as you know Smile).

I tried replacing the Date-gt variable with both DatePosted and LastModified fields that I have in my default.cfg file.

I did create a select field menu for the whats_new_days variables using the build_fancy_select_field mod.

The problem is that when I select a number of days out of range of either the two "Date" variables, I get results of records added today. For example, I select 14 Days and type in a keyword in the search form. I get back records added today.

Does this make sense? Am I missing something here?

To test this for yourself, go to:

anthrotech.com/cgibin/classifieds/

Click on the Main Menu Link.

Click on "List All Jobs". Then use the search form I have in my search results page. Select a number of days other than Today.

Smile

TIA.

------------------
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

[This message has been edited by Eliot (edited August 16, 1999).]

[This message has been edited by Eliot (edited August 16, 1999).]

[This message has been edited by Eliot (edited August 16, 1999).]

[This message has been edited by Eliot (edited August 16, 1999).]

[This message has been edited by Eliot (edited August 16, 1999).]

[This message has been edited by Eliot (edited August 16, 1999).]

[This message has been edited by Eliot (edited August 16, 1999).]

[This message has been edited by Eliot (edited August 16, 1999).]

[This message has been edited by Eliot (edited August 16, 1999).]
Quote Reply
Re: Most recent In reply to
 
Quote:
I made a "what's new in the past x days" sort of mod, which you can pick up at
http://www.jpdeni.com/dbman/whatsnew.txt

There was an error in it, but I fixed it today.

Hi Carol,

As you may recall, I was one of the early users of this wonderful mod. Actually, I think its official creation came out of my encouragement. Wink

I'm curious what the error is that you refer to above. The quoted message is about a month and a half after the version that I'm using, but I can't see any differences.

Thanks,
Dan
Quote Reply
Re: Most recent In reply to
Eliot--

I got a 500 Error when I tried to access the link you gave.

You say
Quote:
I tried replacing the Date-gt variable with both DatePosted and LastModified fields that I have in my default.cfg file.

Did you use DatePosted-gt and LastModified-gt?

Quote:
I did create a select field menu for the whats_new_days variables using the build_fancy_select_field mod.

Could you show me the code you used, please?

Dan--

I'm sorry, but I don't recall what the problem was that I fixed. Smile If it's working, then great!

It may be that, when I made the mod, I didn't put in exactly the same code as I had given you. I just don't remember. Sorry. Smile


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





Quote Reply
Re: Most recent In reply to
Carol,

I noticed that 500 Internal Server Error when I was editing my post. For some reason, my ISP is playing games with me. I tried everything from taking out the additional URL Referrer checker routine to changing the file name to another "appropriate default" file name. But I still get a 500 Internal Server when I try to access the DBMAN project from an external link. Weird!

Anyway, with regards to this thread....

Yes, I did replace the Date-gt with DatePosted-gt and then I tried LastModified-gt to no avail.

Here are the codes I have in the sub query in db.cgi:

Code:
sub query {
# --------------------------------------------------------
# First let's get a list of database fields we want to search on and
# store it in @search_fields

my ($i, $column, @search_fields, @search_gt_fields, @search_lt_fields, $maxhits, $numhits, $nh,
$field, @regexp, $line, @values, $key_match, @hits, @sortedhits, $next_url, $next_hit, $prev_hit,
$first, $last, $upper, $lower, $left, $right, $restricted);

local (%sortby);
if ($in{'new'}) {
$in{'DatePosted-gt'} = &get_date(time() - (($in{'new'}+1) * 86400));
}
if ($in{'whats_new_records'}) {
open (DB, "<$db_file_name") or &cgierr("error in search.
unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
$number_of_records = scalar(@lines);
$target_record = $lines[$number_of_records - ($in{'whats_new_records'} + 1)];
@data = &split_decode($target_record);
$in{"$db_key-gt"} = $data[$db_key_pos];
}

# First thing we do is find out what we are searching for. We build a list of fields
# we want to search on in @search_fields.

if ($in{'keyword'}) { # If this is a keyword search, we are searching the same
$i = 0; # thing in all fields. Make sure "match any" option is
$in{'ma'} = "on"; # on, otherwise this will almost always fail.
foreach $column (@db_cols) {
if (($db_sort{$column} eq 'date') or &date_to_unix($in{'keyword'})) {
$i++;
next;
}
if ($i == $auth_user_field) { $i++; next; }
push (@search_fields, $i); # Search every column
$in{$column} = $in{'keyword'}; # Fill %in with keyword we are looking for.
$i++;
}
}
else { # Otherwise this is a regular search, and we only want records
$i = 0; # that match everything the user specified for.
foreach $column (@db_cols) {
if ($in{$column} =~ /^\>(.+)$/) {
($db_sort{$column} eq 'date') and (&date_to_unix($1)
or return "Invalid date format: '$1'");
push (@search_gt_fields, $i); $in{"$column-gt"} = $1; $i++; next; }
if ($in{$column} =~ /^\<(.+)$/) { ($db_sort{$column} eq 'date') and (&date_to_unix($1) or
return "Invalid date format: '$1'");
push (@search_lt_fields, $i); $in{"$column-lt"} = $1; $i++; next; }
if ($in{$column} !~ /^\s*$/) { ($db_sort{$column} eq 'date') and (&date_to_unix($in{$column}) or
return "Invalid date format: '$in{$column}'");
push(@search_fields, $i); $i++; next; }
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); }
$i++;
}
}

Here is what I have in the build_fancy_select_field sub-routine in html.pl:

Code:
'new' => [
['---','Choose one of the following:'],
['1','Today'],
['3','Last 3 Days'],
['4','Last 4 Days'],
['5','Last 5 Days'],
['7','Last 7 Days'],
['14','Last 14 Days'],
['21','Last 21 Days'],
['30','Last 30 Days'],
['60','Last 60 Days'],
['90','Last 90 Days'],
],

I hope this can shed some light.

Thanks for your assistance.

Regards,
Quote Reply
Re: Most recent In reply to
For the heck of it and to also test my date routines, I add the whats new records drop down menu using the build_fancy_select_field mod. And it works just fine.

Still having problems with the whats_new_days, which I have renamed to "new".

I did fix the access problem to the URL. The problem was that the check_url sub-routines I added had syntax errors all over the place, so I took them out.

You can now access the site at:

anthrotech.com/cgibin/classifieds/

1) Click on the Main Menu link.
2) Click on List All Jobs link.
3) Use the "Short Search Form" in the search result pages. Select a large number of days.
And search for Development.

See, I am still having problems. Are there some "hidden" fields that I need to add to the short search form that will make the drop-down menu work??

Thanks.

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: Most recent In reply to
Seems to work okay for me. The problem is with the "Today" link. It gives a record that was added yesterday.

I'm not sure how you would get around that. Unless you used

if ( exists $in{'new'}) {

in sub query. (Not sure if that will work, but it might.)

Earlier you said

Quote:
The problem is that when I select a number of days out of range of either the two "Date" variables, I get results of records added today. For example, I select 14 Days and type in a keyword in the search form. I get back records added today.

The day you wrote this -- 16 Aug -- there were only records added on that day, unless you have deleted earlier records. That's the only day you could get returned from a search.

Realize that, when anyone selects the number of days they consider new, the search will return records from that day and every day after that, up to the present.

So, if today I select 7 days, I will have records returned that were added any time from 11 Aug through today.



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





> >