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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:46:45+00:00 2026-05-27T00:46:45+00:00

I have the following 2 tables: — members — |member_ID|nick_name| ——————— | 1 |

  • 0

I have the following 2 tables:

         --  members --

      |member_ID|nick_name|
      ---------------------
      |    1    |   Jack  |
      ---------------------
      |    2    |   Jill  |
      ---------------------

           -- shares --

|member_ID|nick_name|percent_owner|
-----------------------------------
|   1     |  Jack   |     75      |
-----------------------------------
|   2     |  Jill   |     25      |
-----------------------------------

My first php page will query the members table and create an html table just fine. In the html table, I added a blank text box to manually enter the percent owner value. This is what that table looks like:

<table>
  <?php foreach ($members as $members) : ?>
  <tr>
    <td><?php echo $members['member_ID']; ?></td>
    <td><?php echo $members['nick_name']; ?></td>
    <td><input type="text" name="percent_owner[]" value="" size="3"></td>
  </tr>
  <?php endforeach; ?>
</table>

Now, what I am trying to do is send the new information to another page to create another html table with the member_ID, nick_name, and percent owner. This where my problem lies. Here is the 2nd html table:

<table>
  <?php foreach ($members as $member) : ?>
  <?php foreach ($_POST['percent_owner'] as $value) : ?>                
   <tr>
     <td><?php echo $member['member_ID']; ?></td>
     <td><?php echo $member['nick_name']; ?></td>
     <td><?php echo $value; ?></td>                 
   </tr>
  <?php endforeach; ?>
  <?php endforeach; ?>
</table>

I don’t believe I am organizing my foreach statements properly. Either I get only the first percent_owner value in every row, or I get both in each row, but cannot get it right. Once I have this figured out, I will then enter it all into the shares table but that will come later. I need to tackle this first.

thank you!

  • 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-27T00:46:45+00:00Added an answer on May 27, 2026 at 12:46 am

    You need to be able to match the data entered to the row it is applied. One way to do it is to add a hidden value to each row with the member id parallel to the percent owner. Theoretically they will both end up with the same index in their respective arrays and you just need to match that up. But that is an ugly and unreliable way to do it.

    Another way you can handle this (definitely the better of the two ways) is to set the name of the user input field for percent owner to be percent_owner_[member id] when your building the form field in the table. Then when you submit the form you can just iterate through the POST variables looking for the sub-string of “percent_owner_” and when you identify those inputs you extract the member id and the user-entered value and save it to an indexed array. Then you use the extracted id to query the DB for other member information.

    Example form fields:

    <table>
      <?php foreach ($members as $members) : ?>
      <tr>
        <td><?php echo $members['member_ID']; ?></td>
        <td><?php echo $members['nick_name']; ?></td>
        <td><input type="text" name="percent_owner_<?=$members['member_ID']?>" value="" size="3"></td>
      </tr>
      <?php endforeach; ?>
    </table>
    

    Then on submit you would process it like this:

    <?php
    foreach ($_POST AS $input => $value) {
      if (stristr($input, 'percent_owner_')) {
        $memberID = str_replace('percent_owner_', '', $input);
        $res = mysql_fetch_object(mysql_query("SELECT nick_name FROM members WHERE member_ID = '$memberID'"));
    
        $data[$memberID] = array(
          'memberID' => $memberID,
          'nickName' => $res->nick_name,
          'percentOwner' => $value
        );
      }
    }
    ?>
    
    <table>
      <?php foreach ($data as $member) : ?>
      <tr>
        <td><?php echo $member['memberID']; ?></td>
        <td><?php echo $member['nickName']; ?></td>
        <td><?php echo $member['percentOwner']; ?></td>
       </tr>
      <?php endforeach; ?>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following tables in MySQL.(I am using php/mysql) CREATE TABLE `hw_subjects` ( `id`
I have following tables format: members mem_id | mem_name ------------------ 1 A 2 B
I have following mysql tables. 1. members ---------- |id |name| ---------- |001|aaa | |002|bbb
I have following tables questions -> id, question_data, user_id users -> id, fname, lname
Suppose that we have following tables create table Employee( 2 EMPNO NUMBER(3), 3 ENAME
I have the following tables: users +----------+----------+----------+ | id | name | dob |
I have the following tables in my database: Products ID_PRODUCT PRODUCTNAME PRICE Customers ID_CUSTOMER
I have the following tables. I want to run a query but I think
I have the following tables. I wanted it so when I make more boxes
I have the following tables in SQL Server 2005 ReceiptPoint: ID (PK), Name GasIndexLocation:

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.