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

 Massive updates in my record

Print topic Send  topic

Author Message
mtsoulis

Posts: 17
Posted: 05/03/2016, 3:01 AM

Hi!
I have a record form "stusers" which include 2 listboxes:
"classbefore" and "classnow"
I would like to make a massive update to my data base Control Source "classst" changing the class all of my students which they are studying in the class of the listbox "classbefore" to the class of the listbox "classnow"
I'm beginner in Code Charge Studio and I will appreciate any detailed advice
Thanks in advance,
Miltos, Greece
_________________
Miltos-Greece
View profile  Send private message
pbarkley

Posts: 37
Posted: 05/03/2016, 8:11 AM

Hi Miltos. I will assume that you have a table called STUDENT and one called CLASS, and that one STUDENT can have one to many CLASSs, to use data modeling spelling. But for some reason you have a class that is not correct, the Class Before. If this is a one time error, for example because you accidentally connected 200 students to the wrong class, then I would just go directly into MySQL (if that's what you're using) and simply update the table. It would look something like this:

UPDATE class
SET ClassID = 37 WHERE ClassID = 15

However, if you have students who were really in ClassID = 37, and a group who were accidentally put in there, that will change their records as well. So I don't know enough about what you're doing.

If what you have, is a group of students who routinely move from one class to a more advanced class each year, or each semester, and you only track their current class, then this will work. I would not even consider writing a CCS page to do this since it's very easy to do directly in the database. If you use MySQL, you probably have access to phpMyAdmin and can do this.

By the way, if your problem is because you have connected your students to a class that is just plain wrong, like "Archimedes 101" when that class doesn't exist or is spelled wrong, you can simply correct the name of the class and your problem will go away. I doubt that your problem is that simple, but sometimes that is the case and we make the solution more complicated than it needs to be. :-)

Also, let's say that you are capable of making the change in the database directly, but you must write a program for someone else to do this every year. If the problem is like I first stated, then you know that eventually you will need to write SQL that is exactly like I wrote out, but instead of actual numbers (37 and 15 that I made up), the user will choose them from two list boxes. If that is the case, then you will create a page, say for a record, so you have a nice form to start with, and then remove everything you don't need and add the two listboxes. In addition, you will add a button that says perhaps "Update Class". I usually put it to the left of the Submit button before I delete the Submit and Cancel buttons--it's just faster to build a page this way in my opinion.

Let's say your form name is class because it's named for your table, and your two listboxes are ListBoxBefore and ListBoxAfter. Then in the Server OnClick event for the new button, you will add code something like this:

$c1 = $class->ListBoxBefore->GetValue();
$c2 = $class->ListBoxAfter->GetValue();

if ($c1 == NULL OR $c2 == NULL) {
// Don't process anything. Perhaps send them to an error dialog or page.
} else {
// Make the transfer.
$db = new clsDBConnection1();
$SQL = "UPDATE class SET ClassID = " . $c2 . " WHERE ClassID = " . $c1;
$db->query($SQL);
$db->close();
}

As a suggestion, I NEVER just write SQL code and then test it in the program, because there are too many things that can go wrong. So after the $SQL line above, I always add when testing:

echo $SQL;
die();

Then your program will stop there and you will see exactly what the SQL says on the screen. I then copy and paste that into phpMyAdmin if it looks OK and test it. Very often I find there is something small that is incorrect, like a missing space or an extra period or something. When you run this in your program and nothing happens (!), you won't know why. If you run it in phpMyAdmin, you will probably see a complaint about where the error is so you can fix it.

I have tried to be as explicit as I can, but if this doesn't answer your question, let me know. When I started with CCS I made many mistakes, and sometimes they were very small errors that still caused huge problems because it is hard to see what CCS is doing. I would strongly suggest that you insert debugging code like the echo/die code above, write a few lines of code, test them, and then remove the code or just move it down and test the next few lines. You don't want to write 30 lines of code and find that nothing works. Good luck!

Regards,
Paul
View profile  Send private message
eratech


Posts: 513
Posted: 05/03/2016, 6:34 PM

Quote pbarkley:

As a suggestion, I NEVER just write SQL code and then test it in the program, because there are too many things that can go wrong. So after the $SQL line above, I always add when testing:

echo $SQL;
die();

Then your program will stop there and you will see exactly what the SQL says on the screen. I then copy and paste that into phpMyAdmin if it looks OK and test it.

Another method to display the SQL is to set the '$Debug' variable to 1 (default is 0) in the file db_mysqli.php (around line 30) when testing and just publish that file. This will print all queries executed at the top of a page. You can copy/paste them and test them individually.

Note that they DO NOT stop them being executed, so you should do something like Paul suggests to stop execution for initial testing.

Cheers

Eric
_________________
CCS 3/4/5 ASP Classic, VB.NET, PHP
Melbourne, Victoria, Australia
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.

PHP Reports

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

Home   |    Search   |    Members   |    Register   |    Login


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