Gossamer Forum
Home : Products : DBMan : Installation :

Record 17 of 2

Quote Reply
Record 17 of 2
I'm starting a new thread here.

I just noticed this problem. I did a search and the link in the short display of the second record sent me to 17 of 2. There was no data in the view fields, but it seemed OK in the edit field.

I commented out the new code JPDeni cacame up with (the class array), and all seems back to OK.

I pasted this code into sub html_record, just before you define the short display.
Perhaps there is a better place to put it?

CODE:
#next section added JPD/FMN 6/4/99 #class_name_array
#
#$teacher1_field = 9; # Change this to match the number of the field where the teacher's id is
#$class1_field = 10; # Change this to match the number of the field where the class name is
#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*$/;
# $line1 = $_;
# chomp ($line1);
# @fields1 = &split_decode ($line1);
# if ($fields1[$teacher1_field] eq $db_userid) {
# if (!(grep $_ eq $fields1[$class1_field], @classes1)) {
# push (@classes1, $fields1[$class1_field]);
# }
# }
# }
#close DB;
Quote Reply
Re: Record 17 of 2 In reply to
That's probably not the best place to put the list of classes.

What I need you to tell me is what page do you want the list to appear on? What do you want users to do before they see the list? Should they just log on? Should they do a search first?

Until I know what you want, I can't answer you.


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





Quote Reply
Re: Record 17 of 2 In reply to
The first place that I would want to use an element from the array is the Main Menu, because that is where I'll place the pre-defined search link, and use the element to name link.
Quote Reply
Re: Record 17 of 2 In reply to
Okay. That helps a lot. Put the code in sub html_home. Don't try to work on the link yet. Just list out the classes for the teacher. You should get a list of the class names, with no repeats.

A question: Are you going to know ahead of time who the teachers are and what classes they teach? This could be done much simpler by defining a hash of the teachers' userids and the classes they teach.


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





Quote Reply
Re: Record 17 of 2 In reply to
Yes, I will know the name of the teachers, (all of them will be users, and their userid will ba a match with their name in the "teacher_name" field) but not the name of their classes.

I'm lost when you say "list out the classes" I don't know how to list the elements.

I'm not able to print even with the "$classes[0]" which worked before.

Also, to clarify, all elements (should only be two in this test) of this array should be identical. This is the array of first period class names taught by this teacher.
Quote Reply
Re: Record 17 of 2 In reply to
Okay. Let's start from scratch.

In html_home, before you do anything else, add the following code. (This is the same as before, but I can't follow a script unless it's indented.)

Code:
$teacher1_field = 9; # Change this to match the number of the field where the teacher's id is
$class1_field = 10; # Change this to match the number of the field where the class name is
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*$/;
$line1 = $_;
chomp ($line1);
@fields1 = &split_decode ($line1);
if ($fields1[$teacher1_field] eq $db_userid) {
if (!(grep $_ eq $fields1[$class1_field], @classes1)) {
push (@classes1, $fields1[$class1_field]);
}
}
}
close DB;

Is there a reason you added "1"s to everything?

If you've got the default text on the html_home page, right after

print " None " if (!($per_view | | $per_add | | $per_del | | per_mod));

add

Code:
foreach $class (@classes1) {
print "$class<BR>";
}

That should put the name of the classes for the teacher on the home page, one class name per line.

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

I just read over your last post. You said that all the elements of the array should be identical. They won't be identical. Or at least they shouldn't be. The code is supposed to pick up the unique values for the field.

If you want a list that includes multiples of the same class name, then I must not be understanding what you want to do.






[This message has been edited by JPDeni (edited June 04, 1999).]
Quote Reply
Re: Record 17 of 2 In reply to
Hi Carol,
I'm tired -about done for the day, but thought that I'd run it up for another go.

I replaced the code, as per your request.

OK - now, the array will not print. But, if I add $classes1[0] as the name of the link, it does. I added it the same way to the short display, but it won't print there.

So, I added $classes[0]$classes[1]$classes[2]$classes[3]$classes[4]$#classes to see what I could get.

$#classes returns only a 1 every time (though there are multiples in the database for some users).

Depending on which userid I log in for, the class name does come up under $classes[0] or $classes[1].

The print command is printing $class which I don't see in the array.

This is the line from sub html_footer that I used to get the elements printed from
CODE:
print qq!| <A HREF="$db_script_link_url&Userid=$db_userid&ID=*&Class1=$classes[0]&sb=0&modify_form=1">0=$classes1[0]|1=$classes1[1]|2=$classes1[2]|#=$# classes1</A> ! if ($per_view);


END CODE
Here's the menu. Sorry but I seem to loose the format when I paste from or to the posts.

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

$teacher1_field = 9; # Change this to match the number of the field where the teacher's id is
$class1_field = 10; # Change this to match the number of the field where the class name is
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*$/;
$line1 = $_;
chomp ($line1);
@fields1 = &split_decode ($line1);
if ($fields1[$teacher1_field] eq $db_userid) {
if (!(grep $_ eq $fields1[$class1_field], @classes1)) {
push (@classes1, $fields1[$class1_field]);
}
}
}
close DB;


#end of added Mod_class_name_array
#


$page_title = "Main Menu";
&html_page_top;

# < -- Start page text -- >
print qq|
<$face size="1"><b>
Permissions:
|;
print " View " if ($per_view);
print " Add " if ($per_add);
print " Delete " if ($per_del);
print " Modify " if ($per_mod);
print " Admin " if ($per_admin);
print " None " if (!($per_view | | $per_add | | $per_del | | per_mod));
print " $classes1[0] ";
print qq|</b></font>

END CODE

[This message has been edited by FMNewman (edited June 05, 1999).]

[This message has been edited by FMNewman (edited June 05, 1999).]
Quote Reply
Re: Record 17 of 2 In reply to
Okay. Now I know what you want. Next, I need to know how your database is set up.

I don't mean to ignore your questions, but I really need to know what's going on before I can answer them.



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





Quote Reply
Re: Record 17 of 2 In reply to
I'm still not sure what you want the link to do. (I'm really not trying to be dense. Smile )

This is what I understood that you wanted in the beginning.

A teacher logs on. He sees a list of the classes he teaches. He clicks on one of the links and it gives him the list of students in that class from which he can choose which, if any, student's information he wishes to modify.

The above is not what you want? If not, I'll need to know, it that sort of terms, what you want to happen.

The reason your array value won't print in the short display is that it's not defined at that point. (Really bad explanation, but I don't know how to explain it well.)

To keep the formatting of code, use
Code:
at the beginning of the code (I added spaces so I could show it without having it actually do the formatting) and use
at the end of the code.



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





Quote Reply
Re: Record 17 of 2 In reply to
Yes, your explanation is just what I want.

The data for ALL teachers period 1 classnames is in class1_field. For period 2 is in class2_field etc.

I understand about the array placement affecting it's being defined.

The array @classes1 only holds period 1 data.
That array seems to hold only 1 element with data, and that element is not in the same position for every userid.

I don't understand that.

I'm also trying to solve the problem of printing.
Quote Reply
Re: Record 17 of 2 In reply to
Yeah, OK.

I set up a new db, called demo.
You can run it from:
http://www.technologyconsultants.com/cgi-bin/DBM/db.cgi?db=demo

Also, uploaded the .cfg .pl and .db files for you to see at
http://www.technologyconsultants.com/DBM

Thanks a lot
Fred
Quote Reply
Re: Record 17 of 2 In reply to
Okay. Now I get it. Smile

To get your list of classes that a teacher teaches, use:

Code:
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[3] eq $db_userid) {
$classes[1] = $fields[4]
}
if ($fields[6] eq $db_userid) {
$classes[2] = $fields[7]
}
if ($fields[9] eq $db_userid) {
$classes[3] = $fields[10]
}
if ($fields[12] eq $db_userid) {
$classes[4] = $fields[13]
}
if ($fields[15] eq $db_userid) {
$classes[5] = $fields[16]
}
close DB;

Then, when you want to print them out, you can use

Code:
for ($class=1; $class<6; ++$class) {
if ($classes[$class]) {
print "$classes[$class]<BR>";
}
}

This would probably be better if it were set up with two databases, one for classes and one for students, but this should work.

Once we get this to working, we'll get your links built.


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