Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Need to loop code on limit check

Codes here !

Moderators: macek, egami, gesf

Need to loop code on limit check

Postby Bluesplayer » Tue Mar 12, 2013 12:58 pm

Hi

I have a great many feeds to refresh. Sometimes these feeds will fail to connect properly and can fill my database up with nonsense. I have managed to lessen the damage caused by building in a limit check which works perfectly. What I would like to do is for the code to run another 2x at least when it hits the limit because in nearly all situations it will then connect to the feed correctly, whereas without a refresh (manual) the feed is deleted further on down the line. The code for refreshing the feeds is this:

Code: Select all
    // ------------------------------------------- refresh product feed
    } else if (isset($_GET['fd_refresh'])) {


    $fdrefresh = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'feedMemory".$_GET['fd_refresh']."'");
    $refresh = mysql_fetch_assoc($fdrefresh);

    $pieces = explode("-:-", $refresh['value']);
       
    $fdURLfeed = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'csvURL".$_GET['fd_refresh']."'");
    $URLfeed = mysql_fetch_assoc($fdURLfeed);
    $fdtypeFeed = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'csvType".$_GET['fd_refresh']."'");
    $typeFeed = mysql_fetch_assoc($fdtypeFeed);
    $fdcompressionFeed = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'compression".$_GET['fd_refresh']."'");
    $compressionFeed = mysql_fetch_assoc($fdcompressionFeed);

       if ($typeFeed['value'] == 'tab') {
       $typeFeed = "\t";
       } else {
       $typeFeed = $typeFeed['value'];
       }

    // set row variable and open file
    $row = intval($pieces[11]);
       if ($compressionFeed['value'] == 'gzip') {
       $handle = fopen('compress.zlib://'.$URLfeed['value'], "r");
       } else {
       $handle = fopen($URLfeed['value'], "r");
       }

    // empty the table
    $empty = "DELETE FROM affiliSt_products1 WHERE prodDB IN ('".$_GET['fd_refresh']."')";
    mysql_query($empty);

    // start auto inc from last ID in db
    $autoinc = mysql_query("SELECT prodID FROM affiliSt_products1 ORDER BY prodDB DESC LIMIT 1");
    $autoincnum = mysql_fetch_assoc($autoinc);
    $resetautoinc = mysql_query("ALTER TABLE affiliSt_products1 AUTO_INCREMENT = ".($autoincnum['prodID']+1)."");

    // while loop with fgetcsv sorts the csv into the data array
    while (($data = fgetcsv($handle, 3000, $typeFeed)) !== FALSE) {

    if ($row == 60000) {
        break 1;
    } 

       $resulta = $pieces[0];
       if ($data[intval($pieces[1])] == NULL) {
       $resultb = $row;
       } else {
       $resultb = $data[intval($pieces[1])];
       }
       $resultb = $data[intval($pieces[1])];
       $resultc = ucwords(strtolower($data[intval($pieces[2])]));
       $resultd = ucwords(strtolower($data[intval($pieces[3])]));
       $resulte = ucwords(strtolower($data[intval($pieces[4])]));
       $resultf = $data[intval($pieces[5])];
       $resultg = $data[intval($pieces[6])];
       $resulth = $data[intval($pieces[7])];
       $resulti = $data[intval($pieces[8])];
       $resultj = $data[intval($pieces[9])];
       $resultk = $pieces[10];
       $resultm = $data[intval($pieces[14])];
       $resultn = $data[intval($pieces[15])];
       $resulto = $data[intval($pieces[16])];
       $resultp = $data[intval($pieces[17])];
       $resultq = $data[intval($pieces[18])];
       $resultr = $data[intval($pieces[34])];
       $results = intval($row);
       
       if ($pieces[12] == 'before') {
       $resulth = $pieces[13].$resulth;
       } else if ($pieces[12] == 'after') {
       $resulth = $resulth.$pieces[13];
       }

    // remove characters that may interfear with navigation or display
       include("../includes/fixlist.inc.php");
       
       $resultc = str_replace($andAmps, " and ", $resultc);
       $resultd = str_replace($andAmps, " and ", $resultd);
       $resulte = str_replace($andAmps, " and ", $resulte);
       $resultc = str_replace($charquotes, "", $resultc);
       $resultd = str_replace($charquotes, "", $resultd);
       $resulte = str_replace($charquotes, "", $resulte);
       $resultb = str_replace($allCharacters, "-", $resultb);
       $resultc = str_replace($allCharacters, " ", $resultc);
       $resultd = str_replace($someCharacters, " ", $resultd);
       $resulte = str_replace($allCharacters, " ", $resulte);
       $resultj = str_replace($currencyCharacters, " ", $resultj);
       $resultl = $_GET['fd_refresh'];

    // miss out headers row
       if ($row != 0) {
       // insert all the data into the database table
          $sql = sprintf("INSERT INTO affiliSt_products1 (
        
                  merchant,   
                merchantProdID,    
                prodCategory,   
                prodName,    
                prodBrand,    
                prodDescription,    
                prodPromoText,    
                prodLink,    
                prodImageURL,    
                prodPrice,
                prodCurrency,
                prodDB,
                extraFieldA,
                extraFieldB,
                extraFieldC,
                extraFieldD,
                extraFieldE,    
                prodImageSmall,    
                dbProdID
                
                ) VALUES (
                
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s
                )",
                quote_smart($resulta),
                quote_smart($resultb),
                quote_smart($resultc),
                quote_smart($resultd),
                quote_smart($resulte),
                quote_smart($resultf),
                quote_smart($resultg),
                quote_smart($resulth),
                quote_smart($resulti),
                quote_smart($resultj),
                quote_smart($resultk),
                quote_smart($resultl),
                quote_smart($resultm),
                quote_smart($resultn),
                quote_smart($resulto),
                quote_smart($resultp),
                quote_smart($resultq),
                quote_smart($resultr),
                quote_smart($results));
          mysql_query($sql, $databaseConnect) or die(mysql_error());
       }
       
       $row++;
    }


As you can see the above has a limit of 60000 entries and if that limit is reached it breaks out of the loop. How to make it repeat the full loop 2x say on hitting 60000 before it breaks out of the loop?
Bluesplayer
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Mar 12, 2013 12:47 pm

Re: Need to loop code on limit check

Postby johnj » Thu Mar 14, 2013 8:12 pm

I did not understand this fully but if you want the control to loop 2x times in hitting 6000,then please change the "if" condition accordingly.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1470
Joined: Thu Mar 10, 2011 5:07 pm

Re: Need to loop code on limit check

Postby Bluesplayer » Fri Mar 15, 2013 1:11 am

I think I have this working now. I added a for loop at the beginning like this:
Code: Select all
// ------------------------------------------- refresh product feed
} else if (isset($_GET['fd_refresh'])) {

//  *** insert for loop here ***
for ($repeat = 0; $repeat < 3; $repeat++) {


Thanks
Bluesplayer
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Mar 12, 2013 12:47 pm

cheapest Herve Leger on sale (51)

Postby griffis99 » Sun May 12, 2013 4:06 am

The article on GMAT is intended to share my on going battle with the GMAT score and also share some handy tips on beating the GMAT.
GMAT (Graduate Management Admission test), the name says it all.
The GMAT test is an important entry point in to various graduate management programmes offered by leading B-schools. The race to finish amongst the high GMAT scores is really one battle worth a view if you are not involved yourself. However, with me its different. Cracking the GMAT has been my obsession for the past 2 years now. It is not that I have failed or not been up to the mark in my previous attempts. Well, herve leger blue the benchmark or expectations out of every GMAT taker are really sky high.
Having completed my GMAT registration 2 years back I was sure I will sail through in the first go. Well, herve leger polyvore I thought I had an ace GMAT prep under my belt to achieve my target. I had mugged up online resources and all I got was a GMAT score of 600 which was not enough to assure me a seat in my target business school. And I tried again the next year which was again a quote unquote disappointment, fetching me a GMAT score of herve leger dresses uk 614. That is when I told myself that my target GMAT score is 700+ and I will get there no matter what. Period!
To achieve my target GMAT score I knew I had to overhaul cheap herve leger dresses uk a lot of wrongs in my GMAT prep and come up with an ace winning GMAT strategies to scale the Everest. I got in touch with a GMAT guru who was a top GMAT coach and learnt some basic strategies which I intend to touch upon with this write-up.
Because of the online and adaptive nature of the GMAT I was told to be in tune and improve my time management white herve leger skills. I did this by introducing online GMAT mock tests in my GMAT prep. I have also discarded outdated GMAT books and now I am only consulting top GMAT books which is bound to have a positive impact on my GMAT prep.
These tips from my GMAT guru has surely helped me and I am herve leger knock off dresses sure the results would now reflect on my GMAT test schedule.

Related articles:


cheapest Herve Leger on sale (34)
griffis99
New php-forum User
New php-forum User
 
Posts: 40
Joined: Mon Dec 17, 2012 12:41 am


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.