Gossamer Forum
Home : Products : DBMan : Customization :

New Twist on User Record Limit and more

Quote Reply
New Twist on User Record Limit and more
I have a few questions... I am trying to create a weight loss database whereby each member may keep track of his or her weight on a weekly basis and then graph the results over time. I've put off this project for a long time due to my inability to find a suitable graphing script. I've found one now, but need help exporting the data to it, plus a couple other things also.

1. Is there a way to limit users to one record per week? (Just when you thought there were no other permutations, too!) If not, this isn't essential. It'd be nice, though.

2. Is there a way to pull the data from one field of the last record to another field in the current record? I want to pull the "weight" field from the last record to this record's "LastWeight". Carol, you helped me last year do something similar through sub get_defaults in db.cgi but in that case it was always pulling from "yesterday's" record so I'm not quite sure how to pull it in this case.

3. Then, finally, the thing that should hopefully pull this all together... the graphing script (in PHP) I found requires two arrays to create the graph. The format is $names = array(1, 2, 3, 4, 5) and so forth, and $values = array(1, 2, 3, 4, 5) and so on. What do I need to do to get the results of a search and place all instances of "Week" in the $names array and all instances of "Weight" in the $values array that can be processed through a hidden field on a form?

(The database is set up so that each user may only view, modify, delete, etc his or her own records, so the search will only return that user's records. Also, the ID is the username plus the date [i.e., guest03-Jul-2000] which was set up in a previous journal to prevent more than one entry per day...I thought it would work well in this database as well. )

hmmm...think I've covered everything. Just hope it makes sense. Thanks!


Melanie
http://www.somemoorecats.com/
http://www.okhima.org/
Quote Reply
Re: New Twist on User Record Limit and more In reply to
One record per week? It would have to be in the line

if (($data[$auth_user_field] eq $db_userid) && ($data[$db_date_field] eq &get_date)) {

Hmmmmm.

It would need to count record if the date field of the record was less than 7 days before today.

I think I've got it.

if (($data[$auth_user_field] eq $db_userid) && ((&date_to_unix($data[$db_date_field]) + 604800) > &date_to_unix(&get_date)) {

(The above code should all be on one line.)

In Reply To:
Is there a way to pull the data from one field of the last record to another field in the current record?
You don't make things easy, do you? Smile

I think you could do this -- again in sub get_defaults. Just before

return %default;

add

Code:

$in{$db_cols[$auth_user_field]} = $db_userid;
$in{'mh'} = 1;
$in{'sb'} = the number of your date field;
$in{'so'} = "descend";
my ($status,@hits) = &query("view");
if ($status eq 'ok') {
my (%rec) = &array_to_hash(0,@hits);
$default{'FieldName'} = $rec{'FieldName'};
}


That should give you the most recent record for the user.

Regarding your graph, can you give me an example of the filled-in hidden fields? I'm not clear on the structure the data needs to be.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: New Twist on User Record Limit and more In reply to
In Reply To:
It would need to count record if the date field of the record was less than 7 days before today.
I think I've got it.
if (($data[$auth_user_field] eq $db_userid) && ((&date_to_unix($data[$db_date_field]) + 604800) > &date_to_unix(&get_date))){
Thanks! Works like a charm! I did add one more close parentheses ")" at the end (added above).

In Reply To:
You don't make things easy, do you?
Now where would be the fun in that? No, really, thanks! Again, it works very well. I was able to use that example and add in the other pieces of data I wanted to default in also.

In Reply To:
Regarding your graph, can you give me an example of the filled-in hidden fields? I'm not clear on the structure the data needs to be.
It seems that the way PHP handles arrays via html forms is to create an input field for each value in the array, with the name of the field the same for all items in that array. uh...okay, I lost myself in that explanation. Here's an example:
<input type="hidden" name="names[]" value="1">
<input type="hidden" name="names[]" value="2"> and so on, where "value" is each instance of $rec{'Week'}. There will be a hidden input field for each item in the array, and they will display in the order in which the appear in the form.

Same goes for the weights...<input type="hidden" name="values[]" value="150"> and so on, with value equalling $rec{'Weight'}.

Make more sense or still clear as mud? Thanks a lot for your help!



Melanie
http://www.somemoorecats.com/
http://www.okhima.org/
Quote Reply
Re: New Twist on User Record Limit and more In reply to
I don't know. [whimper, whimper] Smile

I think I'm missing a step somewhere in here and I don't know where it is.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: New Twist on User Record Limit and more In reply to
hmm....lessee...

If it helps, you can check out the database at http://www.somemoorecats.com/...an/wdb.cgi?db=weight (using username and pw guest/guest -- that's all that's in the DB right now) and the form that creates the graph at http://www.somemoorecats.com/testgraph.html. (You can see the form field code by viewing the source. I left the input fields visible but hidden works, too.)

The way I envision it (but my thought processes may well be totally off the wall), a user could select an option similar to "view my entries" sorted in ascending order which basically searches and retrieves all their records, then goes through a "foreach" loop, and prints a line of code for each record found, with that code being the hidden input field for the form. Even if it's a two step process, that'd be okay, too, so that one button or link creates the hidden form fields and a second button submits the form to generate the graph. Does this make things any clearer at all?

Thanks!

Melanie
http://www.somemoorecats.com/
http://www.okhima.org/
Quote Reply
Re: New Twist on User Record Limit and more In reply to
So you have a field that is Week, right?

(I really don't know what's wrong with me these days. I think I'm just startin' ta get old! Smile Yes, it makes it a whole lot clearer to see the form. Thanks!!!)

What you need to do, then, is get all of the records for that user, sort them by date, and then print out your hidden fields. I think I can do that! Smile

The code below assumes that you have a field called Week and a field called Weight.

Code:

sub create_graph_form {
$in{$db_cols[$auth_user_field]} = $db_userid;
$in{'sb'} = the number of your Week field;
my ($status,@hits) = &query("view");
my ($numhits) = ($#hits+1) / ($#db_cols+1);
my (%tmp);
print qq|all of your form header stuff|;
for (0 .. $numhits - 1) {
%tmp = &array_to_hash($_, @hits);
print qq|
<input type="hidden" name="names[]" value="$tmp{'Week'}">
<input type="hidden" name="values[]" value="$tmp{'Weight'}">
|;
}
print qq|<input type="submit" name="submit" value="submit">
</form>|;
}
Wherever you want to print it out, just use

&create_graph_form;

(make sure it's not within a "print" statement.)



JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: New Twist on User Record Limit and more In reply to
Hi! I hope no one minds if I butt in here on the discussion. Actually, I would very much like to know where did the original poster got the script to churn out a graph. You see, I can creating a feedback form and would very much like to be able export the results of the forms in a graphical manner.

Would very much appreciate if the owner would share this piece of info with me. Thanks.

Julian
Quote Reply
Re: New Twist on User Record Limit and more In reply to
Great! That works beautifully! (I did add a $in{'so'} = ascend; after the $in{'sb'} line so that it would sort from beginning to end rather than in reverse. Smile )

Thank you so much! I've been wanting to do this particular database for a long time but have had trouble finding a good graphing script to work with. I appreciate your help!


Melanie
http://www.somemoorecats.com/
http://www.okhima.org/
Quote Reply
Re: New Twist on User Record Limit and more In reply to
Julian, no problem. The script is located at http://www.webguys.com/...rograms/html_graphs/ and is called HTML_Graphs. It's in PHP and is quite easy to use with several different graph formats available.


Melanie
http://www.somemoorecats.com/
http://www.okhima.org/