CodeCharge Studio
search Register Login  

Web Reports

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

YesSoftware Forums -> CodeCharge Studio -> PHP

 Mass change a database field

Print topic Send  topic

Author Message
ckroon

Posts: 869
Posted: 08/04/2007, 12:39 PM

Hi all. On my school database we need a way to mass change a database field. If a teacher ups and quits they don't want to have to go and change all his/her student's 'teacher_id" field by hand.
I know I could make na Editable grid, to make it easier but I was wondering if I could have two listboxes one for hte current teacher one for the new teacher.

I am hoping for some PHP code that would find every teacher_id in Listbox1 and replace it with the teaher_id in Listbox2.

Am I dreaming?

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

Posts: 583
Posted: 08/04/2007, 1:15 PM

you could copy the teacher record. then let the new record keep the OLD teacher info. Edit the OLD teacher record to contain the NEW teacher info. voila! every student now has the correct (NEW) teacher. of course this could screw up historical reporting.
_________________
Walter Kempees...you are dearly missed.
View profile  Send private message
datadoit.com
Posted: 08/04/2007, 2:57 PM

Create a form with the two fields: Current Teacher and New Teacher.
Make both those listboxes as you want. The datasource for the form can
be any table you want. Doesn't matter since we're not changing any data
there.

Make the form Insertable. Then, in the Current Teacher field's
OnValidate event, add something like this:

global $DBConnectionNameDB;

$Container->InsertAllowed = false; //Don't really allow an insert.

$db = new clsDBConnectionNameDB();
$db->query("SELECT teacher_id FROM yourtable WHERE teacher_id='" .
$Component->GetValue() . "'");
while ($db->next_record()) {
$db2 = new clsDBConnectionNameDB();
$db2->query("UPDATE yourtable SET teacher_id=" .
$Container->NewTeacher->GetValue() . " WHERE teacher_id=" .
$db->f("teacher_id"));
$db2->close();
}
$db->close();

There may be other mo'better ways to skin this cat, but this oughta work
- though not tested. Toss in a buncha echo's before really writing
anything.

ckroon

Posts: 869
Posted: 08/05/2007, 4:37 AM

WOW it worked! Sweet!

Thanks Datadoit! That cat was skinned nicely. :-D
_________________
Walter Kempees...you are dearly missed.
View profile  Send private message

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.