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 7399899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:07:16+00:00 2026-05-29T04:07:16+00:00

I have a for loop that writes the results of a query into a

  • 0

I have a for loop that writes the results of a query into a table. I have a variable ($rID_s) that is being assigned from a value in the query. For some reason, it omits the first iteration. I have a variable for the total rows of the query and it is assigning the correct number. I’ve tried setting $i = 0 and $i = 1 and it still omits the first iteration of the array. If $i is set to 0, it adds a null record to the table.

See below, the value for $rID_s is the variable that is not being assigned on the first iteration of the loop. Thanks in advance:

for ($i=1; $i <= $totalRows_rsClassReg; $i++) {

        $row = mysql_fetch_array($rsClassReg);
        $rID_s = $row['class_registry_student_ID_fk'];

        mysql_select_db($database_SCOPE_test, $SCOPE_test);
        $sql_aInstance = sprintf("INSERT INTO assignment_registry (assignment_reg_assignment_ID_fk, assignment_reg_student_ID_fk) VALUES (%s, %s)",
                    GetSQLValueString($aID, "int"),
                    GetSQLValueString($rID_s, "int"));
        $Insert_aInstance = mysql_query($sql_aInstance, $SCOPE_test) or die(mysql_error());
        echo $row['class_registry_student_ID_fk'] . " - ";
        echo "Instanced";
        echo "</br>";
    }
  • 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-05-29T04:07:17+00:00Added an answer on May 29, 2026 at 4:07 am

    You did not provide enough information to answer your question, so I’m going to totally left field you and provide another way of doing this that should make your question obsolete.

    There are a lot of things you could and should be doing differently here. Imagine that your queries to your database are a bus and each query is a bus trip. It is better to fill up your bus with more data, then to take multiple bus trips.

    // do this up here
    mysql_select_db($database_SCOPE_test, $SCOPE_test);
    
    if( ! empty( $oneDimensionalArrayOfIds ) ){
        $query = " SELECT `col` FROM `table` WHERE ( ". implode( 'AND', $oneDimensionalArrayOfIds ) ." ) ";  // the 1-D array is getting your r_IDs or whatever
        $rsClassReg = sqlarr( $query );
        if( ! empty( $rsClassReg ) ){
            $sqlInserts = NULL;
            foreach( $rsClassReg as $r ){
                $sqlInserts[] =  sprintf("INSERT INTO assignment_registry (assignment_reg_assignment_ID_fk, assignment_reg_student_ID_fk) VALUES (%s, %s)", GetSQLValueString($aID, "int"),  GetSQLValueString($rID_s, "int"));  
                // not sure where you are getting AIDs from (africa?  har har)...
            }
            if( ! empty( $sqlInserts ) ){
                sqlquery( implode( "; ", $sqlInserts ) );
            }
        }
    }
    

    Here’s a freebie – A long time ago, I used to use these functions. Now a days, I use a custom query maker and PDO and save myself a lot of work. Here you go…

    function sqlarr($sql, $numass=MYSQL_BOTH) {
        // MYSQL_NUM  MYSQL_ASSOC  MYSQL_BOTH
        $got = array();
        $result=mysql_query($sql) or die("$sql: " . mysql_error());                             
    
        if(mysql_num_rows($result) == 0)
            return $got;
        mysql_data_seek($result, 0);
        while ($row = mysql_fetch_array($result, $numass)) {
            array_push($got, $row);
        }
        return $got;
    } 
    
    // Sql fetch assoc
    function sqlassoc($sql){
        $query = mysql_query($sql) or die("$sql:". mysql_error());
        $row = mysql_fetch_assoc($query);
        return $row;
    }
    
    function sqlrow($sql){
        $query = mysql_query($sql) or die("$sql:". mysql_error());
        $row = mysql_fetch_row($query);
        return $row;
    }
    
    function sqlquery($sql){
        $query = mysql_query($sql) or die("$sql:". mysql_error());
        return $row;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly simple python loop that calls a few functions, and writes
I have a loop that builds a table with camera names. In that table
I have to write a query to database, that has such table: TABLE HISTORY:
I have a snippet of code that writes the data alphabetically from a database
I have a MySQL query that looks like this: UPDATE `Table` SET `Column` =
I have a loop that reads each line in a file using getline() :
I have a loop that finds duplicate lines in a .ini file. I can
I have a loop that runs through a variety of websites and I'd like
I have a loop that runs for approx. 25 minutes i.e 1500 seconds. [100
I have a loop that calculates the similarity between two documents. It collects all

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.