1

I have a page full of small html tables, each representing data from a database table. This is a one page print out report, so there are quite a few fields across these html tables, but only about 4 or 5 of them may need to be changed.

When the user chooses a record and the report is displayed, all the tables look great but I'm trying to find a way to edit and save the 4 or 5 that might need editing. I know I can create a form with inputs and turn certain table rows into inputs and then with a submit button I can attach a SQL statement to update those fields based on a primary key in the DB table.

How can I actually get these table rows to be editable inputs within a form? I've wrapped the whole page in a form and I even tried by wrapping just one table in a form as a test but I think the problem is my syntax for the table row.

Here is what I tried so far:

<form>
<table style="width:100%; border:none;
border-collapse:collapse;">

    <tr style="border:none;">
        <th style="border:none; text-align: left;" >Meter Test</th>
        <th style="border:none;">Test 1</th>
        <th style="border:none;">Test 2</th>
        <th style="border:none;">Test 3</th>
        <th style="border:none;">Test 4</th>
        <th style="border:none;">Test 5</th>
        <th style="border:none;">Test 6</th>
        <th style="border:none;">Test 7</th>
        <th style="border:none;">Test 8</th>
    </tr>
    <tr style="border: none;" >
        <td style="border:none; text-align: left;">Test Rate GPM: </td>
        <td><? echo $row['test1TestRateGPM'];?>&nbsp;</td>
        <td><? echo $row['test2TestRateGPM'];?>&nbsp;</td>
        <td><? echo $row['test3TestRateGPM'];?>&nbsp;</td>
        <td><? echo $row['test4TestRateGPM'];?>&nbsp;</td>
        <td><? echo $row['test5TestRateGPM'];?>&nbsp;</td>
        <td><? echo $row['test6TestRateGPM'];?>&nbsp;</td>
        <td><input type="text" value = "<?php $row['test7TestRateGPM'];?>">
        <td><input type="text" value = "<?php $row['test8TestRateGPM'];?>">        </td>

    </tr>
    </table>
    </form>

You can see i have the normal html table syntax but for the field I'm testing, I tried it by creating a line of php and doing it that way, but still no form on the web page.

8
  • 2
    You could use the contenteditable attribute. Commented May 8, 2017 at 17:38
  • 1
    look into jquery datagrid Commented May 8, 2017 at 17:40
  • 3
    You use Javascript to retrieve the edited contents. Commented May 8, 2017 at 17:42
  • 2
    Another solution is to just put <input> fields in the table. Commented May 8, 2017 at 17:42
  • 1
    It should be <?php echo $row['test7TestRateGPM'];?> you're missing the echo. Commented May 8, 2017 at 17:56

1 Answer 1

2

I think you just need a simple input text field. Do it like this:

<td><input type="text" value = "<?php echo $row['test1TestRateGPM'];?>"></td>

And make multiple of these.

Sign up to request clarification or add additional context in comments.

7 Comments

Thank you, I just tried this (with form tags around just this table) and it's still not editable on the web page
Can you explain what is still not editable? What I just wrote, you need to do for each <td> separately.
Missing echo in the PHP
But it should still be editable, it just won't have the old value showing.
How did you write it?
|

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.