Creating form fields on certain table rows that echo php values - php

I have a page that displays about 12 tables that are filled from database values. These values correspond with a single record but some of these fields are based off of queries I'm making so that if something's wrong in the query, it will display red text.
I'm only doing this for a few different fields but I want an option to edit and fix those fields and then save them to the database with an UPDATE.
Basically, I don't want to wrap the whole page in a form since only a few fields in a few of the tables will need to be editable. Is there a way to do this so that I can edit only the few fields that need to be fixed?
Here's a table as example:
<div class="testResults" style=" width: 30%; clear:both; float: left;">
<!--Test Results Table-->
<table style="width: 100%;">
<tr>
<th colspan="2">Test Results</th>
</tr>
<tr>
<td style="text-align: left;">Tested Within AWWA Standards</td>
<td><? echo $row['standards'];?> </td>
</tr>
<tr>
<td style="text-align: left;">Meter Failed on Low Side</td>
<td><? echo $row['lowFail'];?> </td>
</tr>
<tr>
<td style="text-align: left;">Meter Failed on High Side</td>
<td><? echo $row['highFail'];?> </td>
</tr>
<tr>
<td style="text-align: left;">Meter Failed Low and High Side</td>
<td><? echo $row['bothFail'];?> </td>
</tr>
<tr>
<td style="text-align: left;">Unable To Test</td>
<td><? echo $row['unableTest'];?> </td>
</tr>
</table>
So, for example, say I want to edit the data for just standards row and lowFail row.
I know once this is done I'll need to have a submit button that attaches to a query to update with the input name, but right NOw i'm trying to find the best way to edit.
Is it easiest to just wrap the whole page in a form and just create the few inputs where I need?

Related

TCPDF not printing table rows containing colspan?

I am trying to print this table in TCPDF, the table is rendering fine but it is totally skipping the <tr> row with colspan , this happens to the only row that has the first <td colspan="8"> cell with a colspan.
This is the html table tha:
<table style="font-size:7px;line-height:16px;border:none;" dir="ltr" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:17%;"></td>
<td>YTD</td>
<td>2019</td>
<td>2018</td>
<td>2017</td>
<td>2016</td>
<td>2015</td>
<td>2014</td>
</tr>
<tr>
<td>Portfolio</td>
<td>-3.63%</td>
<td>14.51%</td>
<td>-5.11%</td>
<td>11.16%</td>
<td>8.48%</td>
<td>-2.13%</td>
<td>2.45%</td>
</tr>
<tr>
<td>Benchmark </td>
<td>-1.64%</td>
<td>9.78%</td>
<td>-3.84%</td>
<td>7.37%</td>
<td>2.92%</td>
<td>-2.66%</td>
<td>0.08%</td>
</tr>
<tr>
<td colspan="8">Morningstar USD Cautious Allocation</td>
</tr>
<tr>
<td></td>
<td>
<p class="double-line">Annualised Return</p>
</td>
<td>
<p class="double-line">Standard Deviation</p>
</td>
<td>
<p class="double-line">Sharpe Ratio</p>
</td>
<td colspan="4"></td>
</tr>
<tr>
<td>Portfolio</td>
<td>4.45%</td>
<td>5.72%</td>
<td>0.78</td>
<td colspan="4"></td>
</tr>
<tr>
<td>Benchmark </td>
<td>2.08%</td>
<td>2.44%</td>
<td>0.85</td>
<td colspan="4"></td>
</tr>
</tbody>
</table>
output on the browser page is fine (see image)
but output on the PDF removes that row completely:
The issue is solved, the problem was not in TCPDF, It was the table not having a proper closing tag for the row </tr> . The table above was coming from a custom field storing it in the DB of a wordpress site. Since the html is generated through a php code I had minor coding error that I forgot to close the row with </tr>. However when viewing the html content in a wordpress WYSWIG editor , it adds the self closing tags. When you debugging it on the browser page also most browsers add auto closing tags. These made me think that the html structure of the table is good and should be an issue with TCPDF. After checking the HTML in the database I finally figured out the table row wasn't closing properly.
Hopefully this will help someone having a similar issue in the future.

How to display devnagri font from INPUT to a php page

I have one php page in which I have changed font for input to devnagri. I need to display it in next php page and also need to insert those to mysql.
first page index.php contains this details......
<table width="535" height="54" border="1">
<tbody>
<tr>
<td height="23">नाम</td>
<td><input type="text" name="name" id="name" style="font-family: Preeti">
</td>
</tr>
<tr>
<td height="23">काम</td>
<td><input type="text" name="job" id="job" style="font-family: Preeti">
</td>
</tr>
</tbody>
</table>
my second page post.php contains
<table width="535" height="54" border="1">
<tbody>
<tr>
<td height="23">नाम</td>
<td><?php
echo $_POST['name'];
?></td>
</tr>
<tr>
<td height="23">काम</td>
<td><?php
echo $_POST['job'];
?></td>
</tr>
</tbody>
</table>
when I type कला in name and खेप in job input
it displays relative english letters on the 2nd page .....
where as I need to display as it displays in input.
I also need to insert those input to mysql and again need to display those mysql data to another page....
I am not getting the way to display and stuck at this point so insert and select query is yet to be done....
Need help to figure it out.
Thanx a lot Phil.
<table width="535" height="54" border="1">
<tbody>
<tr>
<td height="23">नाम</td>
<td style="font-family: Preeti"><?php
echo $_POST['name'];
?></td>
</tr>
<tr>
<td height="23">काम</td>
<td style="font-family: Preeti"><?php
echo $_POST['job'];
?></td>
</tr>
</tbody>
</table>
It has displayed preeti font...
Still INSERT and SELECT query is remaining.

I want a drop down option will be selected in class=item_circle and save it in mysql

I want a drop down option will be selected in class=item_circle and save it in
MySQL. Is there any answer? I'm getting single data in MySQL
database but not the selected one:
<table class="table table-bordered" id="crud_table">
<tr>
<th width="10%">CIRCLE</th>
<th width="10%">Item1</th>
<th width="10%">Item1</th>
<th width="10%">Item1</th>
<th width="10%">Item1</th>
<th width="2%"></th>
</tr>
<tr>
<td contenteditable="false" class="item_circle">Bus Stand</td>
<td contenteditable="true" name="amt" class="item_1"></td>
<td contenteditable="true" name="amt" class="item_2"></td>
<td contenteditable="true" name="amt" class="item_3"></td>
<td contenteditable="true" name="amt" class="item_4"></td>
<td></td>
</tr>
</table>
I don't know if that's what you've asked for (because sorry but your question is a little bit cryptic), but you can just send the data you want to write into the database by either an AJAX request, or, in the case of a drop-down menu as you said, by assigning a value-attribute to each dropdown entry and then sending that via a form to the backend script.

Creating input field from html table that has PHP value

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'];?> </td>
<td><? echo $row['test2TestRateGPM'];?> </td>
<td><? echo $row['test3TestRateGPM'];?> </td>
<td><? echo $row['test4TestRateGPM'];?> </td>
<td><? echo $row['test5TestRateGPM'];?> </td>
<td><? echo $row['test6TestRateGPM'];?> </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.
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.

Jquery change table cell value if other cell contains word

I have a basic table and need to change a word if one of the other cells in that row contains a word.
<table>
<tr class="veh-row">
<td class="vehicle_desc">RED CAR</td>
<td>4000 miles</td>
<td class="veh-trans">Manual</td>
<td>Petrol</td>
</tr>
<tr class="veh-row">
<td class="vehicle_desc">RED CAR</td>
<td>4000 miles</td>
<td class="veh-trans">Manual</td>
<td>Petrol</td>
</tr>
<tr class="veh-row">
<td class="vehicle_desc">RED CAR AUTO</td>
<td>4000 miles</td>
<td class="veh-trans">Manual</td>
<td>Petrol</td>
</tr>
</table>
So I need if td.vehicle_desc contains the word AUTO then Manual will change to Automatic in td.veh-trans. How can I do this and only effect that row and not all other rows?
You can use :contains
$('td.vehicle_desc:contains(AUTO)').siblings('.veh-trans').text('Automatic')

Categories