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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.