Programming Theory
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesProgramming Theory

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old January 10th, 2008, 09:26 AM
spiritssight spiritssight is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 13 spiritssight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 50 m 53 sec
Reputation Power: 0
Filtering script (IT WORKS :-) )

Hello All,

My script after a week now is done, I have been at it for hours on end every day and I can say it works it works :-) now I know there can be improvements in the code and maybe a function or two could be used, but I don't know much and this is what I was able to do to get my script to work. I used a lots of if() statements in it

I am hoping someone can help me write this code better so it can do the job and not kill the server as it does if I set the var (result_c) to more then 813 now I know this will be better with better code and changes made to the server also maybe.

Any how the filter does exactly that filters data from a table called irs_rawdata it checks to see if its in two different tables if its not in either one then it checks to see if it matches some rules if it does it adds it if it finds a match in allow table then it adds it also to the irs_query table, any how the code kind of tell you whats going on by my echo

Any advice on this script would be grateful.

Sincerely,
Christopher

PHP Code:
<?php

ini_set
('display_errors''ON');
ini_set('error_reporting'E_ALL E_STRICT );

include 
'/home/dev/www/lib/db_config_cr-dev.php';
include 
'/home/dev/www/lib/db_conn-select.php';

// Counts record in table
$query_s "SELECT COUNT(*) FROM irs_rawdata";
$result_s mysql_query($query_s) OR die("Sorry, unable to count the records in the table!");
$result_c mysql_result($result_s0);
$record_count $result_c;

echo 
"There is "$record_count ." records in the irs_rawdata table<br /><br />";

$result_c 850;  // block when sript is done

        // checks to see if sesult_c is greater then zero
        // if so then it runs script
        // otherwise it says there is no more records to process
        
for($i=0$i <= $result_c$i++)
        {
        
//used to display a real number instead of 0
        
$record_id $i 1;

        
// selects and limits it to the first row only and retrives the EIN then return a 1 or 0
        
echo "We are now geting a record to process!<br />";
        
$query_s "SELECT EIN FROM irs_rawdata LIMIT 0,1";
        
$result_s mysql_query($query_s) OR die("Sorry, unable to to select EIN for the first record! <br /> "mysql_error());
        
$record mysql_fetch_assoc($result_s);
        
$count mysql_num_rows($result_s);
            
            if(
$count)
            {
            
// changes long var to short var
            
$fin $record['EIN'];

            
// gets record if there is one in block returns 1 or 0
            
echo "We are now processing record "$record_id" with Fed ID #"$fin ."!<br />";
            
$query_s "SELECT fin FROM block WHERE fin = '$fin'";
            
$result_s mysql_query($query_s) OR die("Sorry, unable to select record: " mysql_error());
            
$record mysql_fetch_assoc($result_s);
            
$count mysql_num_rows($result_s);

                if (
$count == 0)
                {
                echo 
"There was no record found in the \"block\" table!<br />";
                echo 
"We are now checking the \"allow\" table!<br />";
                
$query_s "SELECT fin FROM allow WHERE fin = '$fin'";
                
$result_s mysql_query($query_s) OR die("Sorry, unable to select record: " mysql_error());
                
$record mysql_fetch_assoc($result_s);
                
$count mysql_num_rows($result_s);

                    if (
$count == 0)
                    {
                    echo 
"There was no record found in the \"allow\" table!<br />";
                    echo 
"We are now checking if record "$record_id ." matchs the required criteria!<br />";
                    
$query_is "INSERT INTO irs_query SELECT * FROM irs_rawdata WHERE EIN = '$fin' AND PNO LIKE '%blind%'";
                    
$result_is mysql_query($query_is);
                    
$count mysql_affected_rows();

                        if (
$count)
                        {
                        echo 
"We have successfully added the record to the \"irs_query\" table, it match the criteria!<br />";
                        echo 
"We are now deleting record "$record_id " from \"irs_rawdata\" table!<br />";
                        
$query_d "DELETE FROM irs_rawdata WHERE EIN = '$fin'";
                        
$result_d mysql_query($query_d) OR die("Was unable delete "$fin ." from the db table irs_rawdata! <br />" mysql_error());
                        
$count mysql_affected_rows();

                            if(
$count)
                            {
                            echo 
"We have successfully deleted the record from the \"irs_rawdata\" table!<br /><br />";
                            }
                        }
                        else
                        {
                        echo 
"We was unable to match the record "$record_id ." to the criteria!<br />";
                        echo 
"We are now adding record "$record_id " to \"block\" table!<br />";
                        
$query_i "INSERT INTO block (fin, who_blocked) VALUES ('$fin', 'S-123456789')";
                        
$result_i mysql_query($query_i) OR die("Sorry was unable to insert ".$fin." into the database table allowed! <br />" mysql_error());
                        
$count mysql_affected_rows();

                            if(
$count)
                            {
                            echo 
"We have successfully added the record to the \"block\" table!<br />";
                            echo 
"We are now deleting record "$record_id " from \"irs_rawdata\" table!<br />";
                            
$query_d "DELETE FROM irs_rawdata WHERE EIN ='$fin'";
                            
$result_d mysql_query($query_d) OR die("Was unable to delete ".$fin." from the db table irs_rawdata! <br />" mysql_error());
                            
$count mysql_affected_rows();

                                if(
$count)
                                {
                                echo 
"We have successfully deleted the record from the \"irs_rawdata\" table!<br /><br />";
                                }
                            }
                        }
                    }
                    else
                    {                


                    
$query_is "INSERT INTO irs_query SELECT *  FROM irs_rawdata WHERE EIN = '$fin'";
                    
$result_is mysql_query($query_is);
                    
$count mysql_affected_rows();

                        if (
$count)                            {
                        echo 
"We was sucessfully added / replaced the record in \"irs_query\" table!<br />";
                        echo 
"We are now deleting record "$record_id " from \"irs_rawdata\" table!<br />";
                        
$query_d "DELETE FROM irs_rawdata WHERE EIN = '$fin'";
                        
$result_d mysql_query($query_d) OR die("Was unable delete ".$fin." from the db table irs_rawdata! <br />" mysql_error());
                        
$count mysql_affected_rows();
                        
$count 1;
                            if(
$count == 1)
                            {
                            echo 
"We have successfully deleted the record from the \"irs_rawdata\" table!<br /><br />";
                            }
                        }
                
                    }
                }
                else
                {
                echo 
"There was one record found in the \"block\" table!<br />";
                echo 
"We are now deleting record "$i " from \"irs_rawdata\" table!<br />";
                
$query_d "DELETE FROM irs_rawdata WHERE EIN = '$fin'";
                
$result_d mysql_query($query_d) OR die("Was unable delete ".$fin." from the db table irs_rawdata! <br />" mysql_error());
                
$count mysql_affected_rows();

                    if(
$count)
                    {
                    echo 
"We have successfully deleted the record from the \"irs_rawdata\" table!<br /><br />";
                    }

                }

              }
              else
             {
              echo 
"There is no records in the table!";
              exit;
              }
        }
        echo 
"The computer has finished processing the records in irs_rawdata!";
        
include_once (
'/home/dev/www/lib/db_close.php');
?>

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesProgramming Theory > Filtering script (IT WORKS :-) )


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek