popmotsy Posted April 6, 2009 Share Posted April 6, 2009 hii to all...i have some problam with insert with sum.... consider a table...contains fields mobileno::ifowned::occupation:score... here ifowned and occupation are combobox ,, user can select combobox option according to that some value can selected ,,now i show the sum of selected fields on a page in a input box,,,, now i want to enter that inputbox value of sum into "score" column of same table,,, can any one suggest me query,, also the table contain multiple records ...so here we insert thru making array,,thru foreach statement...here also i got an error "Invalid argument supplied for foreach() " thanks,,, ??? ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/152779-insert-with-sum/ Share on other sites More sharing options...
aschk Posted April 6, 2009 Share Posted April 6, 2009 I recommend you post some code with what you've got so far and what you require (example dataset). Quote Link to comment https://forums.phpfreaks.com/topic/152779-insert-with-sum/#findComment-802266 Share on other sites More sharing options...
popmotsy Posted April 6, 2009 Author Share Posted April 6, 2009 ok.thanks for replying...let me explain ..first i insert the values,, foreach ($_POST['mobileno'] as $row=>$name) { $mobileno= mysql_real_escape_string($name); $occupation=$_POST['occupation'][$row]; $ifowned=$_POST['ifowned'][$row]; $sql="insert into table(mobileno,occupationid,ifownedid,) values ('$mob','$occupation',''$ifowned')" ; } then by this query i show the sum:: SELECT cp. * , sum( ifo.score + oc.score ) AS score FROM tablename AS cp, if_owned AS ifo, occupation AS oc WHERE cp.occupationid = oc.name AND cp.ifownedid = ifo.name GROUP BY cp.mobileno show the value of sum in textbox,,,, now again i want to insert sums into column score ,,i try this query if(isset($_POST['submit'])) { foreach ($_POST['score']as $row=>$name) { $sc=mysql_real_escape_string($name); $sql="insert into table set score='$sc'"; $res=mysql_query($sql)or die(mysql_error()); } } but at this point i got a notice that Invalid argument supplied for foreach() so now what is the mistake,,,, Quote Link to comment https://forums.phpfreaks.com/topic/152779-insert-with-sum/#findComment-802284 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.