Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Thu Dec 13, 2007 8:49 am Reply with quote

I'm trying to update these records to cleanse them from a scantron. I needed to remove any leading x from the StudentID which I did with this.
Code:


$replacexuid = $db->sql_query("UPDATE ".$prefix."$table_name SET StudentID = REPLACE(StudentID,'x','0')");


Then I need to strip off the first character in a 9 character field and replace with a U

Code:
$i = "U";

$alteruid = $db->sql_query("SELECT StudentID FROM ".$prefix."$table_name");
while ($row = $db->sql_fetchrow($alteruid)) {
$clean_UID = substr($row['StudentID'], -8);
      $new_UID = $i.$clean_UID;
$db->sql_query("UPDATE ".$prefix."$table_name SET StudentID = '$new_UID'");
  }


The code is currently updating the very last record out of 104 from the query and updating all student grades with that UID. This is incorrect as each student has their own StudentID.

I missing something that seems pretty easy.
 
View user's profile Send private message Visit poster's website ICQ Number
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Thu Dec 13, 2007 9:22 am Reply with quote

I always dump what my interpreted query will look like to try to resolve the problem. Try modifying your code to read as follows to be sure it is forming your query correctly.

Code:
while ($row = $db->sql_fetchrow($alteruid)) {

   $clean_UID = substr($row['StudentID'], -8);
   $new_UID = $i.$clean_UID;
   $sql = "UPDATE ".$prefix."$table_name SET StudentID = '$new_UID'";
   die('<br />$sql = '.$sql.'<br />');
   $db->sql_query($sql);
}

That will at least let you know if that is or isn't the problem.
 
View user's profile Send private message
Donovan







PostPosted: Thu Dec 13, 2007 9:49 am Reply with quote

The result tells me

Code:
$sql = UPDATE atlas_tl_session_grade_import SET StudentID = 'U00077193'


Which is the first record in the imported table.

But after it finishes it actually takes the last record read and then updates all records with 'U00000110'
 
Donovan







PostPosted: Thu Dec 13, 2007 10:25 am Reply with quote

Maybe something like...

Code:


while ($row = $db->sql_fetchrow($alteruid)) {
   $clean_UID = substr($row['StudentID'], -8);
   $new_UID = $i.$clean_UID;
   foreach ($row['StudentID'] as $new_UID) {
   $sql = "UPDATE ".$prefix."$table_name SET StudentID = '$new_UID'";
   $db->sql_query($sql);
   }
}


But this tells me I have an error with
Code:


  foreach ($row['StudentID'] as $new_UID) {


Quote:

Warning: Invalid argument supplied for foreach()


...repeated 104 times. I guess that is a good sign Laughing
 
Donovan







PostPosted: Thu Dec 13, 2007 1:28 pm Reply with quote

Once I get these imported correctly I have the next thing to do which is to match them to my students table. Since the StudentID may be incorrect I will also need to match on the Student Name.

The Student_Name in the imported table would look something like this:

BERENSON, KATE F

And the field 'Last_Name' in my student table would be:

Berenson

How could I do this in a single query to try and match up each record?

Here is my first attempt... it is pretty rough:

Code:
$iratimported = $db->sql_query("SELECT a.*, strtoupper(b.Name_Last), b.U_Account FROM ".$prefix."_tl_session_grade_import a 

JOIN ".$prefix."_tl_students b WHERE (b.Name_Last LIKE a.StudentName% || b.U_Account == a.StudentID)");


Another option is to split the Student_Name into Name_First and Name_Last when I import the csv. Then I could do without the LIKE operator

An example record of the csv looks like

Quote:

1,000544030 ,"BERENSON, KATE F",9,90,35,9,90
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©