Creating input field from html table that has PHP value - php

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.

Related

How can I select a specific user in the database and show only his info?

I need to build a table that contains user data from the database I've created.
Pretty much, I've sent an auto increment "ID" field in my users table, and now I want do a little multi choice box where all the users that are in the database are shown there. From there, I need them to be selectable.
However, I want the table that I have to show only the data from the user that was selected.
So let's say, for user with user name "John", I want to show on the table the following database fields:
name
route
date
bus_number
When selecting the user, I want all that information to show up on the table, but only his information.
Only thing I've tried so far was to display all the users data in the table so it contains all the names and respective fields.
I'm using this bootstrap table template as a testing resort.
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>#mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>#fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td colspan="2">Larry the Bird</td>
<td>#twitter</td>
</tr>
</tbody>
</table>
The function that grabs the user ID.
function getUserById($id){
global $db;
$query = "SELECT * FROM users WHERE id=" . $id;
$result = mysqli_query($db, $query);
$user = mysqli_fetch_assoc($result);
return $user;
}
I've tried doing a query by ID and limiting to 1, I did not get any output in the table after displaying the information on the table with php echo.
If I understand your problem well, it seems to me that you need to do it like that:
<tbody>
<tr>
<th scope="row">
<input name="userid[]" value="1" type="checkbox" />
</th>
<td>Mark</td>
<td>Otto</td>
<td>#mdo</td>
</tr>
<tr>
<th scope="row">
<input name="userid[]" value="2" type="checkbox" />
</th>
<td>Jacob</td>
<td>Thornton</td>
<td>#fat</td>
</tr>
and then handle the $ids = $_POST['userid'] variable as an array. Change the function getUserById to function getUserById(array $ids)

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 form fields on certain table rows that echo php values

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?

How to create an html link to another page from "<?=$objResult["id"];?>"

I'm working on a php/mysql application and need to make the output of one column, one row an html link to another html page. Have not been able to find any relavant information. The "" needs to be the link. Thanks for any help.
<table id="display" style="width:800px;">
<tr>
<th width="40">ID</th>
<th width="70">Last</th>
<th width="70">First</th>
<th width="10">Middle</th>
<th width="70">Birth</th>
<th width="70">Death</th>
<th width="170">Notes</th>
<th width="100">Cemetery</th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td style='text-align:center;'><?=$objResult["id"];?></td>
<td style='text-align:center;'><?=$objResult["last"];?></td>
<td style='text-align:center;'><?=$objResult["first"];?></td>
<td style='text-align:center;'><?=$objResult["middle"];?></td>
<td style='text-align:center;'><?=$objResult["birth"];?></td>
<td style='text-align:center;'><?=$objResult["death"];?></td>
<td><?=$objResult["notes"];?></td>
<td style='text-align:center;'><?=$objResult["cemetery"];?></td>
</tr>
<?
}
?>
</table>

Setup table column width

I am trying to setup a table column width to only 200px or 10%. However, when I populate the data from the database, the column seems to ignore the column width and expand it as much as it can. Here is my table html.
<table>
<thead>
<tr>
<th><a href='#'>City</a></th>
<th width='200' class='table_width'><a href='#'>name</a></th>
<th><a href='#'>Agent</a></th>
<th>...
//I have tried class and width attribute. both don't work.
</tr>
</thead>
<tbody>
<tr>
//these column data were popluated from database
<td><?= $row->city; ?></td>
<td width='200' class='table_width'><?= $row->_name; ?></td>
//ignore the width and expand the table cell.
<td><?= $row->agent; ?></td>
<td>...
</tr>
You want to use word-wrap:break-word;.
http://jsfiddle.net/RF4F6/1/
HTML
<table>
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
<th>Col 4</th>
<th>Col 5</th>
</tr>
</thead>
<tbody>
<tr>
<td>Normal Width</td>
<td>Normal Width</td>
<td class="forcedWidth">hiThisIsAreallyLongStringThatWillHaveToWrapAt200PixelsOrI'llBeUnhappyAndYouWon'tLikeMeWhenI'mUnhappy.</td>
<td>Normal Width</td>
<td>NormalWidth</td>
</tr>
</tbody>
</table>
CSS
table td{
padding:.5em; /* Not essential for this answer, just a little buffer for the jsfiddle */
}
.forcedWidth{
width:200px;
word-wrap:break-word;
display:inline-block;
}
This is the standard behaviour of a table cell.
One way to do this is place a div inside your cells with style="width: 200px; overflow-hidden;"
Using table-layout: fixed for table will force browser to maintain specified dimensions.

Categories