Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7856803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:49:24+00:00 2026-06-02T20:49:24+00:00

So here is what I am doing. Read a row each in for loop.

  • 0

So here is what I am doing.

  1. Read a row each in for loop. (Because all at once is going to take some resources since I am in a shared hosting.)
    2.Get the right field data to a variable.
    3.Manipulate the req datas dependant on the extracted field.
    4.update the new fields where filed=extracted data.

Bit of addition, I am adding the current position to a file, so that the script can continue from there next time it is run.

Problem : It doesnt seem to work. The counter.txt gets values like 3-4, but it simply resides there. my db has like 1000k rows.

my code :

require ("dbconnect.php");
header("refresh:29;url=process.php"); // so it doesnt ever end. I cant use max_execution_time here for some reason.
$count = mysql_query("SELECT COUNT(*) FROM collection ");
$data = mysql_fetch_array($count);
$count = $data[0];
echo $count;

$countfile = fopen("counter.txt", "r");
$counter = fgets($countfile);
echo fgets($countfile);

while (fgets($countfile) <= $count)
 {
$i = fgets($countfile);
$takeword = mysql_query("SELECT word FROM collection WHERE id='$i'") or die();
$wd = mysql_fetch_array($takeword);
$data = $wd[0];

$d1 = hash($algorith='md2',$data);
$d2 = hash($algorith='md4',$data);



$write = mysql_query("UPDATE collection SET md2='$d1', md4='$d2' WHERE id='$i'") or die(mysql_error());

//opens, empties and write the new pointer to the file. closes, and open the file in readmode for the next read at the loop.
$counts = fopen("counter.txt", "w+");
fwrite($counts, $counter + 1);
fclose($counts);
$countfile = fopen("counter.txt", "r");
}

Any help would be appreciated 🙂 Looking for code optimization and killing the error. Suggestions would do.:)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:49:25+00:00Added an answer on June 2, 2026 at 8:49 pm

    Alright I’d do something like this (sorry about the delayed response, I kept forgetting)

    <?php
        //main execution
        $sql = mysql_connect(...);
        if (!$sql)
            die ("No database connection");
    
        if (!mysql_select_db(..., $sql))
            die ("Database does not exist in this schema");
    
        //Run the query for this iteration.
        processQuery();
        //---
    
        function getQueryOffset($file)
        {
            $offset = 0; //default offset
            if (file_exists($file)) //check if the counter file exists
            {
                $contents = file_get_contents($file); //get the contents of the counter
                if ($contents !== FALSE && is_numeric($contents)) //check if an appropriate counter value
                    $offset = intval($contents);
            }
            return $offset;
        }
    
        function processQuery()
        {
            $table = "collection"; //table to update
            $counter = "counter.txt"; //where to look for the last execution's offset.
            $maxrows = 10000; //update 10,000 rows each time this file is loaded.
            $sql = $GLOBALS['sql'];
    
            //calculate the number of rows in the table
            $qCount = mysql_query("SELECT COUNT(*) max FROM $table", $sql);
            $aCount = mysql_fetch_assoc($qCount);
            mysql_free_result($qCount);
            $max = $aCount["max"];
    
            $offset = getQueryOffset($counter); //calculate the offset (or a default 0)
            if ($offset < $max) //if offet >= max, we're done.
            {
                $qUpdate = mysql_query("SELECT word, id FROM $table LIMIT $offset, $maxrows", $sql); //get the next "maxrows" rows from the table.
                if ($qUpdate) 
                {
                    $assoc = NULL;
                    while (($assoc = mysql_fetch_assoc($qUpdate)) != NULL)
                    {
                        $md4 = hash("md4", $assoc["word"]); //calculate the hashes
                        $md2 = hash("md2", $assoc["word"]); 
                        $id = $assoc["id"]; //id the row
                        mysql_query("UPDATE $table SET md2='$md2', md4='$md4' WHERE id=$id", $sql); //update the table columns
                    }
                    //update the offset in the counter file.
                    file_put_contents($counter, ($offset + mysql_num_rows($qUpdate)));
                    mysql_free_result($qUpdate);
                }
            }
        }
    
        mysql_close($sql);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Doing some homework here (second assignment, still extremely green...). The object is to read
What am I doing wrong here: class Helo { // main: generate some simple
I am not sure what I should be doing here. Should I be hardcoding
What am I doing wrong here folks? <?php include 'header.php'; /** * Display a
What am I doing wrong here? I'm trying to get started with jQuery UI
What is it I am doing wrong here: When I try to use the
What am I doing wrong here? I'm serializing a value, storing it in a
What am I doing wrong here? private void SendMail(string from, string body) { string
What am I doing wrong here? Im trying to save a canvas drawing by
What am I doing wrong here? It says Database Count Failed (on the $count

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.