Jump to content

insert with sum/////////


popmotsy

Recommended Posts

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,,, ??? ??? ??? ???

 

Link to comment
https://forums.phpfreaks.com/topic/152779-insert-with-sum/
Share on other sites

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,,,,

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/152779-insert-with-sum/#findComment-802284
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.