parsing...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
FreeBaGeL
Forum Newbie
Posts: 17
Joined: Sun Jun 27, 2004 5:35 pm

parsing...

Post 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.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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?
FreeBaGeL
Forum Newbie
Posts: 17
Joined: Sun Jun 27, 2004 5:35 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

he meant

Code: Select all

echo "{$sid}:{$did}";
FreeBaGeL
Forum Newbie
Posts: 17
Joined: Sun Jun 27, 2004 5:35 pm

Post by FreeBaGeL »

Awesome, the script now works with your guys help, thanks a million!
Post Reply