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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:50:15+00:00 2026-06-18T09:50:15+00:00

I am not clear how to construct a multidimensional array to create a simple

  • 0

I am not clear how to construct a multidimensional array to create a simple datagrid framework. I have a number of class methods with crud select statements from MySQL tables in the format:

<?php

  function table1()
  {
    $sql = "SELECT * FROM `table1`";
    $result = mysqli_query ($link, $sql);
    $html = "<table>";
    while ($row = mysqli_fetch_array( $result ))
    {
      $html .= "<tr><td>".$row['field_a']."</td><td>".$row['field_b']."</td></tr>";
    }
    $html .= "</table>";
    return $html;
  }

  function table2()
  {
    $sql = "SELECT * FROM `table2`";
    $result_properties = mysqli_query ($link, $sql);
    $html = "<table>";
    while ($row = mysqli_fetch_array( $result ))
    {
      $html .= "<tr><td>".$row['field_x']."</td><td>".$row['field_y']."</td></tr>";
    }
    $html .= "</table>";
    return $html;
  }

?>

where the MySQL tables look like:

table1

+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | bigint(12)   | NO   | PRI | NULL    | auto_increment |
| field_a | varchar(128) | NO   |     | NULL    |                |
| field_b | varchar(128) | NO   |     | NULL    |                |
+---------+--------------+------+-----+---------+----------------+

table 2

+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | bigint(12)   | NO   | PRI | NULL    | auto_increment |
| field_x | varchar(128) | NO   |     | NULL    |                |
| field_y | varchar(128) | NO   |     | NULL    |                |
+---------+--------------+------+-----+---------+----------------+

I am trying to replace all these methods with a single datagrid method, selecting information about each individual table from two summary grid tables – one with properties of each table (table name and the select sql statement for that table) and the other with field names and headings for each individual table:

grid_properties

+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | bigint(12)   | NO   | PRI | NULL    | auto_increment |
| table      | varchar(128) | NO   |     | NULL    |                |
| select_sql | varchar(128) | NO   |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

grid_fields

+--------------------+--------------+------+-----+---------+----------------+
| Field              | Type         | Null | Key | Default | Extra          |
+--------------------+--------------+------+-----+---------+----------------+
| id                 | bigint(12)   | NO   | PRI | NULL    | auto_increment |
| grid_properties_id | bigint(12)   | NO   |     | NULL    |                |
| heading            | varchar(128) | NO   |     | NULL    |                |
| field              | varchar(128) | NO   |     | NULL    |                |
+--------------------+--------------+------+-----+---------+----------------+

Data in the grid_fields.field column is intended to just be the field name of the table referenced in grid_properties.table, related through grid_properties.id::grid_fields.grid_properties_id.

The method I am using to construct the datagrid has a multidimensional array in the last while loop that has something wrong with it. What is the correct way to construct this?

<?php

  function grid_schema($table)
  {
    // Get information about $table from the grid_properties table
    $sql = "SELECT * FROM `grid_properties` WHERE `table` LIKE '".$table."'";
    $result_properties = mysqli_query ($link, $sql);
    $properties = mysqli_fetch_array ($result1);
    $properties_sql = $properties['select_sql'];
    $id = $properties['id'];

    // Get information about the grid field names
    $fields_sql = "SELECT * FROM `grid_fields` WHERE `grid_properties_id` ='".$id."'";
    $fields_result = mysqli_query ($link, $fields_sql);

    // Display the Table Headings
    $html = "<table><tr>";
    while ($fields_row = mysqli_fetch_array ( $fields_result ))
    { $html .= "<th>".$fields_row['heading']."</th>"; }
    $html .= "</tr>";

    // Perform the SQL query from the grid_properties table
    $properties_result = mysqli_query ($link, $properties_sql);
    while ($properties_row = mysqli_fetch_array ($properties_result))
    {
      // Print out the contents of each row
      $html .= "<tr>";
      while ($fields_row = mysqli_fetch_array( $fields_result ))
      {
        // This is where I am having problems
        $html .= "<td>".$properties_row[$fields_row]['field']."</td>";
      }
    }
    $html .= "</table>";
    return $html;
  }
?>
  • 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-18T09:50:17+00:00Added an answer on June 18, 2026 at 9:50 am
    <?php
        function grid_schema($table)
    {
    $link = mysqli_connect("localhost", "root", "", "test");
    
    // Get information about $table from the grid_properties table
    $sql = "SELECT * FROM `grid_properties` WHERE `table` LIKE '".$table."'";
    $result_properties = mysqli_query ($link, $sql);
    $properties = mysqli_fetch_array ($result_properties, MYSQLI_ASSOC);
    $properties_sql = $properties['select_sql'];
    $id = $properties['id'];
    
    // Get information about the grid field names
    $fields_sql = "SELECT * FROM `grid_fields` WHERE `grid_properties_id` ='".$id."'";
    $fields_result = mysqli_query ($link, $fields_sql);
    
    // Display the Table Headings
    $html = "<table><tr>";
        $rows = array();
    while ($fields_row = mysqli_fetch_array ( $fields_result, MYSQLI_ASSOC ))
    {
            $rows[] = $fields_row['field'];
            $html .= "<th>".$fields_row['heading']."</th>";
        }
    $html .= "</tr>";
    
    // Perform the SQL query from the grid_properties table
    $properties_result = mysqli_query ($link, $properties_sql);
    while ($properties_row = mysqli_fetch_array ($properties_result, MYSQLI_ASSOC))
    {
    // Print out the contents of each row
    $html .= "<tr>";
    foreach($rows as $row)
    {
    // This is where I am having problems
    $html .= "<td>".$properties_row[$row]."</td>";
    }
    }
    $html .= "</table>";
    return $html;
    }
    
    echo grid_schema('table1');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not clear on the actual difference between these two styles of class
Not clear on some fundamental syntax here. define-key accepts a set of inputs, one
It's not clear, to me anyway, if a UIView is automatically released from its
It's not clear to me if the Eclipse plugin completely replaces the need to
I'm not clear on the status of XHTML - v1.0 versus v1.1. Can someone
I am not clear from the documentation - when I indicate a cell width
Sorry if question is not clear. My vocabulary for terminology is bad. Anyways I
My question is not clear at title [i can not write it exactly] e.g
It's not clear to me why I'm getting this particular exception, it's a red-herring
I am playing with Autolayout in Cocoa and some things are not clear for

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.