how to post arrays to php -
solved, see final answer post complete details on worked me
*original question , edits below:
looking way set multiple sql items posted array.
i'm pretty sure i'm using php5.
here how set single one, don't know arrays in php
mysql_query (" update comics set xml = updatexml(xml,'comic/pagenumber', '<pagenumber>'.$pagenumber.'</pagenumber>') id = $id ") or die(err(mysql_error()));
i post idarray , newpagenumberarray flash
where comic id of idarray[0] set pagenumber newpagenumberarray[0] , on.
the arrays of equal length each other. of length, depending on number of altered page numbers in admin tool.
for make separate php request per item, think cleaner send them out in 1 php request.
*edit
thanks patrick feel closer... still don't have quite right.
flash sends these arrays
idarr: 34,24
pagenumarr: 1,2
in php have function
function changepagenumbers($con, $idarr, $pagenumarr){ selectdatabase($con); echo '&startforloop=true'; for($i=0;$i<count($idarr);$i++) { $thispagenum = mysql_real_escape_string($pagenumarr[$i]); $thisid = mysql_real_escape_string($idarr[$i]); echo '&thispagenum='.$thispagenum; echo '&thisid='.$thisid; mysql_query (" update comics set xml = updatexml(xml,'comic/pagenumber', '<pagenumber>".$thispagenum."</pagenumber>') `id` = ".$thisid." limit 1; ") or die(err(mysql_error())); echo '&querysent=true'; } echo '&endforloop=true'; }
it returns this
thispagenum=2&endforloop=true&thisid=2&startforloop=true&querysent=true
which seems out of order (maybe that's normal?)
more importantly lists thispagenum , thisid 1 time, when array has 2.
and still more importantly lists thisid = 2. id's sent 34 , 24
*edit2 works when run in html , manually set arrays in php
$idarr = array(34,24); $pagenumarr = array(2, 1);
which means passing arrays through $_post flash, failing in way. i'm constructed arrays in flash. perhaps on way through $_post become comma separated values.
running more tests.
you can send them in 1 request , create loop in php update them 1 one. far know there no way in 1 statement, or have create complex case constructs. might lead better database performance, it's hell of lot more work little sql exprience, should in php.
don't forget start transaction. :)
loop:
foreach($_post['variableofyourchoice'] $id) { // execute query using $id }
Comments
Post a Comment