CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Default a listbox from table

Print topic Send  topic

Author Message
ckroon

Posts: 869
Posted: 07/24/2007, 11:10 PM

Hi all.

Got a listbox in a record that I want defaulted to a previous value from a different table.

I have this code on the Before Show event of the listbox

global $DBConnection1;
$temp = CCDLookUp("math_course", "wrecord_q1", "student_id='stud_id'",$DBConnection1);

No error codes (yay :) ) but it doesn't do it.

Any ideas?

_________________
Walter Kempees...you are dearly missed.
View profile  Send private message
datadoit.com
Posted: 07/25/2007, 5:47 AM

ckroon wrote:
> Hi all.
>
> Got a listbox in a record that I want defaulted to a previous value from a
> different table.
>
> I have this code on the Before Show event of the listbox
>
> global $DBConnection1;
> $temp = CCDLookUp("math_course", "wrecord_q1",
> "student_id=stud_id",$DBConnection1);
>
> No error codes (yay :) ) but it doesn't do it.
>
> Any ideas?
>
> ---------------------------------------

$temp has the value of the lookup, but did you set your listbox control
to this value?

Ex: $Component->SetValue($temp);

You can also 'echo $temp' to make sure it actually has something.
ckroon

Posts: 869
Posted: 07/25/2007, 1:06 PM

So close..

global $DBConnection1;
$Component->SetValue($temp);
$temp = CCDLookUp("math_course", "wrecord_q1",
"student_id='stud_id'",$DBConnection1);

Is on the BeforeShow event of the listbox
I am getting an undefined variable erro from the second line.

I am learning PHP as we speak, but I am still at the beginning stages, this stuff is a bit beyond where my book is right now, but I am gradually getting there.. with all your help of course!

_________________
Walter Kempees...you are dearly missed.
View profile  Send private message
datadoit.com
Posted: 07/25/2007, 1:28 PM

Like this:

global $DBConnection1;
$temp = CCDLookUp("math_course", "wrecord_q1",
"student_id='stud_id'",$DBConnection1);
$Component->SetValue($temp);

or you can say:

global $DBConnection1;
$Component->SetValue(CCDLookUp("math_course", "wrecord_q1",
"student_id='stud_id'",$DBConnection1));
ckroon

Posts: 869
Posted: 07/25/2007, 1:56 PM

hmmm
tried both, no results.. no errors, just an empty listbox. I checked and there is data in the db table.

Thought: does the Where student_id ='stud_id' have to be CCGetfromGet?

_________________
Walter Kempees...you are dearly missed.
View profile  Send private message
datadoit.com
Posted: 07/25/2007, 2:48 PM

ckroon wrote:
> hmmm
> tried both, no results.. no errors, just an empty listbox. I checked and there
> is data in the db table.
>
> Thought: does the Where student_id ='stud_id' have to be CCGetfromGet?
>
> ---------------------------------------

The way it's written, it's expecting the value 'stud_id' in the
student_id field.

Test your lookup by putting in a value that you know is there, such as
'1' or whatever.

Otherwise, use whatever you would need to use for the student id. If in
a session var such as the login ID, use CCGetUserID(), or
CCGetSession("stud_id",""), or a URL parameter CCGetParam("stud_id",""),
etc.

So your lookup could look like this:

$Component->SetValue(CCDLookUp("math_course", "wrecord_q1",
"student_id='" . CCGetParam("stud_id", "") . "'", $DBConnection1));
ckroon

Posts: 869
Posted: 07/25/2007, 3:24 PM

Still not working.
So....

global $DBConnection1;
$Container->Label1->SetValue(CCDLookUp("last_name","classlist","student_id=".CCGetFromGet("stud_id",0),$DBConnection1));

on the Before SHow event of the record form... did the trick!

Thanks Data do it. And Walter.
I managed to piece some posts together, along with your advice on this one to figure out an option that works.

The confusing (but useful) thing about PHP, is that are lots of ways to do one thing.

Grateful for the help and good PHP JuJu for you.

_________________
Walter Kempees...you are dearly missed.
View profile  Send private message
ckroon

Posts: 869
Posted: 07/25/2007, 3:45 PM

Arrrggg!

LOL

Ok. It works, but too well.

I can call the record and it defauls to the value I want, but if I change the value, it records the new value in teh DB, but doesn't reflect hte new change in the listbox.

The poiint of this application is, if you're wondering, for teacher assigning classes to students every quarter of a school year. Rather than have them fill the same courses out every quarter I thought it woud be a time saver to have the previous quarters classes default for them, then they can change the ones that needed changing.

So.. how do I get the code to look at the field, and if it is empty, default it, if there is data there, ignore the code and show the data.

I was so damned excited too, seeing that page show up with no errors!


_________________
Walter Kempees...you are dearly missed.
View profile  Send private message
datadoit.com
Posted: 07/26/2007, 6:22 AM

> So.. how do I get the code to look at the field, and if it is empty, default
> it, if there is data there, ignore the code and show the data.
>
> ---------------------------------------

Same way we were working with the SetValue() function, you can also work
with the GetValue() function. Just enclose your statement in an if
condition. So if there's no value for the field, do this.

if (!$Container->Label1->GetValue())
{
$Container->Label1->SetValue(CCDLookUp("last_name","classlist","student_id=".CCGetFromGet("stud_id",0),$DBConnection1));
}



Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.