is it possible to input a data grid in php like in VB6?
because in my program, user will display lots of data and displaying it in a data grid (clickable) is the best way, we all know that in VB6, once the user clicked anywhere in the grid, it is possible to get the data of the selected row/column..


please help..^_^

Dani AI

Generated

Yes — you can get VB6-style clickable rows in a PHP web app. The usual, robust pattern is: server exposes a small API that returns row details (JSON); the page renders a table or uses a client-side grid component; clicking a row requests the details and displays them in a panel or form. As pointed out, each row needs a stable unique ID; instead of plain links you can store that ID in the DOM (HTML5 data- attributes) and handle clicks with JavaScript for a smoother UI.

Example workflow (minimal):

  • Render rows with a data-id on each <tr> on page load.
  • Use event delegation in JS to catch row clicks, read dataset.id, call fetch() to an API endpoint.
  • The PHP endpoint uses PDO prepared statements and returns JSON for the requested ID.
  • Populate a details panel or form on success.

A compact example (client and server) shows the mechanics without repeating earlier code:

// client: delegate clicks, call API
document.getElementById('grid').addEventListener('click', e => {
  const tr = e.target.closest('tr[data-id]');
  if (!tr) return;
  fetch('/api/row.php', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ id: tr.dataset.id })
  })
  .then(r => r.json())
  .then(showDetails)
  .catch(console.error);
});
// server: api/row.php (use real DSN/creds)
header('Content-Type: application/json');
$input = json_decode(file_get_contents('php://input'), true);
$id = $input['id'] ?? null;
if (!$id) { http_response_code(400); echo json_encode(['error'=>'missing id']); exit; }
$pdo = new PDO($dsn, $user, $pass, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
$stmt = $pdo->prepare('SELECT * FROM items WHERE id = :id LIMIT 1');
$stmt->execute([':id'=>$id]);
echo json_encode($stmt->fetch(PDO::FETCH_ASSOC) ?: []);

Notes and cautions:

  • Never use unescaped input in SQL; prefer PDO/mysqli prepared statements (see PHP PDO docs).
  • For large datasets implement server-side pagination, indexing, or use a grid library with server-side processing (DataTables, ag-Grid, Tabulator).
  • Keep accessibility in mind: keyboard focus, ARIA roles, and visible selection states so the grid works like a native control (see MDN on data-* and event delegation).

Relevant docs: PHP PDO prepared statements (https://www.php.net/manual/en/pdo.prepared-statements.php) and HTML5 data-* attributes (-*).

If the out put data comes from a database, then one can store the row IDs in html anchor tags. Then when the user clicks, sends the stored ID back to sql query for all other data retrieval.

After using sql queries to get the data, you can output in table/grid form.
http://www.w3schools.com/php/php_mysql_select.asp

<table >
      <tr> 
            <th>Something</th>
            <th>Something Else</th>
      </tr> 

<?php
do { ?>
  <tr> 
        <td><a href="myPage.php?id=<? echo $row_stuff['id'];?>"><? echo $row_stuff['stuff']; ?></a></td>
        <td><? echo $row_stuff['more_stuff']; ?></td>
 </tr> 
<?php }while ($row_stuff = mysql_fetch_assoc($stuff));
?>
</table>

You will then need to use PHP $_GET to get the value of the id stored in the url, look here:

Then again use some sql queries to again retrieve the data and output more of that row data or whatever...

$id = $_GET['id'];
$stuff = mysql_query("SELECT * FROM stuff
WHERE id='$id'");

Otherwise, if not from a database, then it depends on the implementation of the data, each row should have a unique identifier, that way when clicked, the identifier can be used to retrieve data specific to itself.

Is this what you are asking?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.