View Single Post
  #1 (permalink)  
Old February 15th, 2007, 04:17 AM
Hylsan Hylsan is offline
Authorized User
 
Join Date: Dec 2006
Location: , , Sweden.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default saving data from a array

Hi
I want to save data from a array.

Database looks like this;
Code:
id  artikel    jan   feb   mars
1     101        0     0      0
2     103        0     0      0        
3     109        0     0      0
and my code looks like this;

Code:
          $artikel = mysql_query("SELECT artikel FROM interndeb") or die(mysql_error('hittar inga artiklar'));

          // HTML-tabellens formatering - tabellstart
          echo "<table border='1' bordercolor='#FFAA2A' bgcolor='#FFFFD4' cellspacing='0' cellpadding='3'>";
          echo "<tr bgcolor='#C4E7C9' align=center><td>Artikel</td><td width='45'>JAN</td><td width='45'>FEB</td><td width='45'>MARS</td><td width='45'>APRIL</td><td width='45'>MAJ</td><td width='45'>JUNI</td><td width='45'>JULI</td><td width='45'>AUG</td><td width='45'>SEP</td><td width='45'>OKT</td><td width='45'>NOV</td><td width='45'>DEC</td><td width='50'>TOTALT</td></tr>";

          #---- Hämtar data och sparar den i interndeb-tabellen ----#
          while($row = mysql_fetch_array( $artikel ))
            {
                 #---- kollar ifall det är dax för art. 130 ----#
                $trans = mysql_query("SELECT *,SUM(nettovikt) as vikt FROM trans where artikel='$row[artikel]' and status='2' and kund='101' and transtid between '2007-01-01 00:00:00' and '2007-01-31 23:59:59' group by artikel;") or die(mysql_error('hittar ingen vikt'));
                $vikt = mysql_fetch_array( $trans );
                echo "artikel:" .$row[artikel];
                echo "  vikt:" .$vikt[vikt] . "<br />";
                if($vikt[vikt]=='')
                {
                    echo "<td align=right>0</td></tr>";
                    $save = "UPDATE interndeb SET jan='0' WHERE artikel='$row[artikel]'";
                    mysql_query($save)or die(mysql_error());
                }
                else
                echo "<td align=right>" .$vikt[vikt] . "</td></tr>";
                $save = "UPDATE interndeb SET jan='$vikt[vikt]' WHERE artikel='$row[artikel]'";
                mysql_query($save)or die(mysql_error());

            }
            echo "</table>";

the output looks like this, including the error message...

Code:
artikel:101 vikt:102
artikel:103 vikt:109.29
Data truncated for column 'jan' at row 2
As you can see the first artikel works fine, but when it comes to the second he wont save the data.

Can anyone help me in the right direction??
Regards
Hylsan

Reply With Quote