Page 1 of 1

parsing...

Posted: Thu Jul 22, 2004 7:13 pm
by FreeBaGeL
Hi, I have a script that allows me to delete multiple rows in one of my database tables with checkboxes.

The problem is that the table has a primary key made of two columns: student ID and detail ID.

Student ID's may hence show up more than once with different detail ID's.

I have the checkbox set up to send the student ID with the box, but because of this, when I delete it deletes the entire student ID from the table, and hence every occurrence of it rather than just the single row I want.

I've only figured out one way to send both the Student ID and the Detail ID with the checkbox, and here it is:

Code: Select all

while(OCIFetchInto($q, $arrGrades, OCI_ASSOC+OCI_RETURN_NULLS)){

   $sid=$arrGrades['STUDENT_ID'];
   $did=$arrGrades['DTL_ID'];
   $name="" . s . "" . $sid . "" . d . "" . $did ."";

   echo '<tr height="28"><td><p align="center"><input type="checkbox" value="';
   echo $name;
   echo'" name="DeleteGrades[]"></td></tr>';
This way it makes the value of the checkbox a string with the letter s, then the value of the student ID, then the letter d, and then the value of the detail ID.

For instance, the checkbox for the row with student ID 7 and Detail ID 11 would have the value "s7d11"

My question is how do I parse this in the processing file? Basically I want to extract just the '7' as the student ID, and the '11' as the detail ID.

I'm doing this in oracle, but any general help is more than welcome as well, thanks.

Posted: Thu Jul 22, 2004 7:35 pm
by nigma
how about instead make each checkboxes value something like:

Code: Select all

studentid:detailid
then later on in php do this:

Code: Select all

list($studentid,$detailid) = explode(":",$checkbox);
then you can delete from database where studentid=$studentid and detailid=$detailid

make sense?

Posted: Thu Jul 22, 2004 9:49 pm
by FreeBaGeL
Sort of, but wouldn't studentid:detailid just put in the strings studentid and detailid? I need it to be the actual values of the variables.

Also, hadn't heard of explode before but upon looking it up it looks like it returns a string. Again I would need the actual variable returned.

Posted: Thu Jul 22, 2004 9:51 pm
by feyd
he meant

Code: Select all

echo "{$sid}:{$did}";

Posted: Fri Jul 23, 2004 12:33 am
by FreeBaGeL
Awesome, the script now works with your guys help, thanks a million!