Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 15th, 2007, 04:17 AM
Authorized User
Join Date: Dec 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default saving data from a array

I want to save data from a array.

Database looks like this;
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;

          $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 />";
                    echo "<td align=right>0</td></tr>";
                    $save = "UPDATE interndeb SET jan='0' WHERE artikel='$row[artikel]'";
                    mysql_query($save)or die(mysql_error());
                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...

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving Data with Report latingntlman Reporting Services 0 March 18th, 2008 04:52 PM
Data Cache not saving rturner003 ASP.NET 2.0 Professional 1 August 8th, 2007 07:29 PM
Error for saving data csharpa SQL Server 2005 0 February 21st, 2007 07:48 AM
Saving Form Data Earl Hickey ASP.NET 1.0 and 1.1 Basics 5 July 25th, 2006 01:10 PM
Saving data from an array into a variable cutovoi Excel VBA 1 January 7th, 2004 10:09 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.