0

I want to create a grid in PHP and display a value in selected cell whose value matching with database cell value.

Grid example:

A1|B1|C1|D1|E1|F1|G1|H1|
A2|B2|C2|D2|E2|F2|G2|H2|
A3|B3|C3|D3|E3|F3|G3|H3|

In database I have a column named cell_address that contain values like [A1,A2,D3,H3];

How can I put the database value within the grid ?

3 Answers 3

3

Try this:

<?php

$cell_address = "[A1,A2,D3,H3]";

$ar_columns = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H');
$ar_rows = array('1', '2', '3');

$ar_addresses = explode(",", substr($cell_address, 1, -1));

$html = "<table>
  <tr>
    <th></th>
    <th>".implode("</td><td>", $ar_columns)."</th>
  </tr>\n";

foreach($ar_rows as $row)
{
  $html .= "<tr><th>".$row."</th>\n";

  foreach($ar_columns as $col)
  {
    $cell_str = (in_array($col.$row, $ar_addresses) ? "match" : "&nbsp;");
    $html .= "<td>".$cell_str."</td>\n";
  }

  $html .= "</tr>\n";
}

$html .= "</table>\n";

echo $html;
Sign up to request clarification or add additional context in comments.

1 Comment

its a good idea. thank you very much. i hv already done it but you hv smart idea and i ll change ur idea with my ...
0

Simply fetch the data from database using mysql_fetch_array() and display it in the grid ...

Comments

0

For questions like this I can only say: read the manual (e.g. this which also contains examples) and study the language basics

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.