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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:18:28+00:00 2026-05-27T03:18:28+00:00

I have the next: $students=array(‘student1′,’student2′,’student3′,’student4’); $date=array(‘date1′,’date2′,’date3’); $students represents the files and $date represents the

  • 0

I have the next:

$students=array('student1','student2','student3','student4');
$date=array('date1','date2','date3');

$students represents the files and $date represents the columns.
For each $student and $date there is a value different.

For example:

  $students['student1']$dates['date1']='value11';
  $students['student1']$dates['date2']='value12';
  $students['student1']$dates['date3']='value13';
  $students['student2']$dates['date1']='value21';

….
…..
etc.

           date1   date2     date3 
   student1   value11  value12  value13
   student2   value21  value22  value23
   student3   value31  value32  value33

I want fill the values in a table.
I want to load these values in a grid dynamically.
The count for $students and $dates change dynamically.
These values filled in a table I need to insert into database.
I need to update the values into database.

My table in database has the follow fields:

id_tabla  estudiante   date    values

1         estudiante1  date1  value11
2         estudiante1  date2  value12
3         estudiante1  date3  value13
4         estudiante2  date1  value21
5         estudiante2  date2  value22
6         estudiante2  date3  value23

can you help me? Thanks.

The $students is genertated by a query in database.
$dates is generated by a range of the dates in php.

The idea is to do a form with text input $students x $dates where the datas should be included. With this form I should get the values datas.

  • 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-27T03:18:29+00:00Added an answer on May 27, 2026 at 3:18 am

    You have quite a lot of requirements and without knowing the context it’s not trivial to choose the right data structure. From your example I guess that you have an array with students and an array with dates. The size of the arrays can change, but you always need to attach the dates-array to each student, right?

    So based on my assumption, I think you don’t need to rearrange the two arrays into one. You can do your enlisted tasks with the given structure.

    Outputting each student with dates in a table:

    <table>
      <?php foreach($students as $student) { ?>
      <tr>
        <td><?php echo $student; ?></td>
        <?php foreach($dates as $date) { ?>
          <td><?php echo $date; ?></td>
        <?php } ?>
      </tr>
      <?php } ?>
    </table>
    

    Inserting in a database:

    <?php
    $insert_dates = "'" . implode("','", $dates) . "'";
    foreach($students as $student) {
      $qry = "INSERT INTO `students` (`name`, `date1`, `date2`, `date3`)
                     VALUES ('" . $student . "', " . $insert_dates . ")";
      //execute query
    }
    

    Updating:

    <?php
      $qry = "UPDATE `students` 
              SET date1='".$dates[0]."', date2='".$dates[1]."', date2='".$dates[2]."' 
              WHERE name IN ('" . implode("','", $students) . "')";
      //execute query
    

    BUT this approach has some obvious flaws concerning the dynamic changes. So if you are going to work with databases, you should build associative arrays with the keys corresponding to the column names of the table:

    $students=array();
    $students[] = array('name' => 'student1');
    $students[] = array('name' => 'student2');
    $students[] = array('name' => 'student3');
    $students[] = array('name' => 'student4');
    
    $dates=array();
    $dates[] = array('date1'=>'15/04/20', 'date2'=>'20/05/15', 'date3'=>'18/11/10');
    

    The dynamic update query would then look like so:

      $set_data = '';
      foreach($dates as $key => $value) {
        $set_data .= $key . "='".$value."',";
      }
      $set_data = substr($set_data, 0, -1); //remove last comma
      $qry = "UPDATE `students` 
              SET " . $set_data . "  
              WHERE name IN ('" . implode("','", $students) . "')";
      //execute query
    

    There’s a whole lot more you can achieve by playing with data structures (e.g., applying and changing the dates for each student individually, choosing the student-name as the key of the associative array so you can access each student by name, etc.). So at first you should figure out what you need the data for and then choose an appropriate structure based on that. I think you get the idea and I hope it helps!


    //UPDATE

    Based on your updated question, I think this could be a good approach for the structure (although I still don’t know where the data comes from and how/if you can populate that array dynamically/programatically):

    $students = array();
    $students[] = array(
      'name' => 'student1',
      'dates' => array(
         'date1' => 'code123kil',
         'date2' => 'dadfdre145',
      )
    );
    $students[] = array(
      'name' => 'student2',
      'dates' => array(
         'date1' => 'daytetyeyy',
         'date2' => 'dafdfe335',
         'date3' => 'code123kil'
      )
    );
    //and so on
    

    So now, let’s output it into a grid:

    <table>
     <?php foreach($students as $student) { ?>
       <tr>
         <td>Name: <?php echo $student['name']; ?></td>
         <td>Dates: <?php echo implode(', ', $student['dates']); ?></td>
       </tr>
     <?php } ?>
    </table>
    

    Insert into a table:

    <?php
    foreach($students as $student) {
      foreach($student['dates'] as $key => $value) {
        $qry = "INSERT INTO `your_table` (`estudiante`, `date`, `values`)
                VALUES ('".$student['name']."','".$key."','".$value."')";
      //execute query
      }
    }
    

    Update the date-values in a table for a given student

    <?php
      //find the given student in the array
      $student_to_update = 'student2';
      $student_info = null;
      foreach($sudents as $student) {
       if($student['name'] == $student_to_update) {
        $student_info = $student;
        break;
       }
      }
    
      //update the student in database:
      if(!is_null($student_info))
        foreach($student_info['dates'] as $key => $value) {
          $qry = "UPDATE `your_table`
                  SET `values`='".$value."'
                  WHERE `estudiante` = '".$student_info['name']."' 
                    AND `date`='".$key."'";
          //execute query
        }
      }
    

    Update the date-values in a table for each student

    <?php
      foreach($students as $student) {
        foreach($student['dates'] as $key => $value) {
          $qry = "UPDATE `your_table`
                  SET `values`='".$value."'
                  WHERE `estudiante` = '".$student['name']."' 
                    AND `date`='".$key."'";
          //execute query
        }    
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have next tables Order , Transaction , Payment . Class Order has some
I'm going to start of by noting that I have next to no python
I have the next function: function setImagesWidth(id,width) { var images = document.getElementById(id).getElementsByTagName(img); for(var i
I have the next query that I run via SQLCMD.EXE use [AxDWH_Central_Reporting] GO EXEC
I have the next query: var bPermisos = from b in ruc.Permisos where b.IdUsuario
I have the next code in javascript. I deleted some unnecessary items because it
I have the next problem: I need to process only 1 request at a
I have the next problem. In one of the cells (UITableViewCell) I need to
I have the next code: Process p = Runtime.getRuntime().exec(args); and I want my program
In my fieldset I have labels next (side) to my textboxes, but for some

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.