problem with format_number and fwrite()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • azura ali
    New Member
    • Aug 2010
    • 7

    #1

    problem with format_number and fwrite()

    I'm try to use fwrite for format numbering to write in text file, but its doesn’t work.

    Code:
    if($result){
          while($array=mysql_fetch_array($result)){
    	     $xsupp = $array['SUPP'];
    		 $xpartno = $array['XPART'] ;
    		 $len = strlen($xpartno);
    		 $xspace = 16 - $len;
    		 $xpartno = $xpartno . str_repeat(" ",$xspace);
    		 $xpn = $array['PN'];
    		 $xcav = $array['tool_cav'];
    		 $xqty1 = $array['QTY'];
    		 $xqty2 = $array['TOTQTY'];
    		 $stqty2 = number_format($xqty2);
    		 $xshot = number_format(round($xqty2/$xcav,0));
    		 $xamt1 = round($array['AMT'],0);
    		 $xamt2 = round($array['TOTAMT'],0);
    		 $stamt2 = number_format($xamt2);
    		 $data = "$xsupp \t $xpartno\t\t  $xpn \t\t $xcav \t\t";
    		 $data2="\t\t";
    		 $data3= " \r\n";
    		    echo ("<tr><th>$xsupp</th><th>$xpartno</th><th>$xpn</th><th>$xcav</th><th align=\"right\">$xshot</th><th align=\"right\">$stqty2</th><th align=\"right\">$stamt2</th></tr>");
    			
    			fwrite($fp,$xpartno);
    			fwrite($fp,$data2);
    			fwrite($fp,$stqty2,integer*4);
         		fwrite($fp,$data3);
        }
    Last edited by Dormilich; Aug 20 '10, 05:51 AM. Reason: added [code] tags, changed title
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    what does not work, writing into the file or formatting the number?

    Comment

    • azura ali
      New Member
      • Aug 2010
      • 7

      #3
      formatting the number is dosent work. writing into file is OK.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        what do you expect the output to be and what format do you get?

        Comment

        • azura ali
          New Member
          • Aug 2010
          • 7

          #5
          i would like to have format number as in the file attachment (pcp032.txt).
          Attached Files

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            what is the output you receive?

            Comment

            • azura ali
              New Member
              • Aug 2010
              • 7

              #7
              file output : please refer to attachment file (output.txt)

              Thanks :)
              Attached Files

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                if you’re talking about the "Shots" numbers, they are formatted correctly.

                Comment

                • azura ali
                  New Member
                  • Aug 2010
                  • 7

                  #9
                  Code:
                  $xqty1 = $array['QTY']; 
                  $xqty2 = $array['TOTQTY']; 
                  $stqty2 = number_format($xqty2); 
                  $xshot = number_format(round($xqty2/$xcav,0)); 
                  $xamt1 = round($array['AMT'],0); 
                  $xamt2 = round($array['TOTAMT'],0); 
                  $stamt2 = number_format($xamt2);

                  how about $stamt2 & $stqty2?
                  is it correct?
                  Last edited by Dormilich; Aug 20 '10, 08:08 AM. Reason: Please use [code] tags when posting code

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    Quantity and Amount are formatted correctly, too.

                    Comment

                    • azura ali
                      New Member
                      • Aug 2010
                      • 7

                      #11
                      is that have any problem with writing into the file? because the output file(output.txt ), for Shot, Quantity & Amount dosent appear in that file output.

                      Comment

                      • Dormilich
                        Recognized Expert Expert
                        • Aug 2008
                        • 8694

                        #12
                        I don’t know where you looked before … but that's your file’s content.

                        Code:
                        ID.PCP0232 						
                        Date : 20-08-2010 
                        
                        	 INCOMING MAT'LS QUANTITY (Mat'l Code = I,J) 
                        
                        
                        Supp 	Part No         	Tool PN         	Cav  	     Shots     	  Quantity  	    Amount    
                          
                        01001	204RRC-340-01E  	204RRC-340-XXE  	    1	     7,312	     7,312	       209 
                        01001	701RRC-113-01E  	701RRC-113-XXE  	    1	     2,443	     2,443	       127 
                        01001	801APG-005-51E  	801APG-005-XXE  	    1	     1,200	     1,200	       838 
                        01002	204RRC-301-01E  	204RRC-301-XXE  	    1	     7,200	     7,200	       936 
                        01007	411LPR-013-02R  	411LPR-013-XX   	    1	     3,000	     3,000	       117 
                        01007	415CCT-018-01M  	415CCT-018-XX   	    1	   120,000	   120,000	    14,952 
                        01007	415LPR-028-31M  	415LPR-028-XX   	    1	    70,000	    70,000	     2,030 
                        01007	415LPR-029-31M  	415LPR-029-XX   	    1	    70,000	    70,000	     2,730 
                        01007	415LPR-031-90   	415LPR-031-XX   	    2	    52,500	   105,000	     2,184 
                        01007	415LPR-032-C0   	415LPR-032-XX   	    2	    32,785	    65,570	     2,144 
                        01007	415LPR-045-30F  	415LPR-045-XX   	    1	   420,000	   420,000	    11,844 
                        01007	415LPR-046-30F  	415LPR-046-XX   	    1	   300,000	   300,000	    11,190 
                        01007	415LPR-047-30F  	415LPR-047-XX   	    1	    40,000	    40,000	     2,060 
                        01007	415LPR-047-31F  	415LPR-047-XX   	    1	   300,000	   300,000	    14,820 
                        01007	503RRC-020-01E  	503RRC-020-XXE  	    1	    30,000	    30,000	     4,422 
                        01013	103RRC-356-02E  	103RRC-356-XXE  	    4	       248	       991	       426 
                        01013	302RRC-269-01E  	302RRC-269-XXE  	    4	     1,500	     6,000	     2,232 
                        01013	302RRC-270-11E  	302RRC-270-XXE  	    4	     1,500	     6,000	     2,232 
                        01013	302RRC-271-01E  	302RRC-271-XXE  	    2	     4,417	     8,834	     6,926

                        Comment

                        • azura ali
                          New Member
                          • Aug 2010
                          • 7

                          #13
                          thats is sample output that i want to look like.(pcp032.tx t)
                          i have attached another attachment file (output.txt) this file is the original output after I run the program.

                          Comment

                          • Dormilich
                            Recognized Expert Expert
                            • Aug 2008
                            • 8694

                            #14
                            $data2 and $data3 are not numbers, but whitespace, you would need $stqty2 to print (var_dump()) to check its actual content. I see you already print results, what does it say regarding the numbers?
                            Last edited by Dormilich; Aug 20 '10, 08:51 AM.

                            Comment

                            Working...