PDA

View Full Version : Saving more than one record


holty
03-10-2004, 02:01 PM
Hi

I have a form which loops through a table displaying all the customer id's, names and date of births where the date of birth is blank. I have a a submit button (save) which will then pass to a page which will call a stored proc to insert into the database.

My question is - how can I pass through x amount of records and get it to update each one?

so my page will look like this:

customer id: 0123 name: joe bloggs dob:
customer id: 0124 name: mike bloggs dob:
customer id: 0125 name: dave bloggs dob:

-------------------save---------------------------

Any ideas?

firepages
03-10-2004, 02:09 PM
what Database? some like MySQL can only do 1 UPDATE at a time

..if so a loop required , assuming form fields in the format ..



<?=$name;?> : <input name="DOB[<?=$customer_id;?>]" /> etc

could be looped through ...

<?
foreach($_POST['DOB'] as $key=>$var){
$sql = "UPDATE $table DOB='$var' WHERE customer_id=$key";
mysql_query($sql) or die(mysql_error());
}
?>


or some similar shenanigans

holty
03-10-2004, 02:46 PM
Hi - thanks for your reply

Its an oracle database that my table is in....

I want to loop through and execute a stored procedure that takes in the customer id and date of birth.

How could i put the customer id and date of birth into an array and loop through it?

Thanks

sad69
03-10-2004, 06:26 PM
Perhaps you know what you want to do, you just don't know how to call the stored procedure in PHP?

In that case, check this link:
http://www.exzilla.net/docs/php-oci8/php-plsql.php

Hope that helps,
Sadiq.

holty
03-11-2004, 08:36 AM
I can call stored procedures no problem - usually i'm updating one record at a time.

this time its different - i have one screen with multiple customer details on - I would like one save button at the end that will call the stored procedure x amount of times.

I know how to call the procedure but its the loop that i'm stuck on!

thanks

sad69
03-11-2004, 05:21 PM
Ok, I'm going to use firepages example since I haven't seen any of your code. And I'm going to integrate the example from the website I posted since I don't know what your stored procedure looks like either.

I'm not 100% sure this is correct, but I think it should give you the idea.


<?php
foreach($_POST['DOB'] as $key=>$var){
$query = "begin get_single_row_details('$myFriendName', :var_ftel); end;";
$stmt = OCIParse($con, $query) or die ('Can not parse query');
OCIBindByName($stmt,":var_ftel", &$myFriendTel, 20) or die ('Can not bind variable');
OCIExecute($stmt) or die ('Can not Execute statment');
}
?>


Now you just have to replace your query with your stored procedure name, and the appropriate values (ie. $key or $var or whatever your stored procedure requires...), and make sure to change the OCIParse line as well.

Hope that works out for you!

Sadiq.