show result into html table from database - php

i have textfield inside html table..i want after i type something like "name" in another cell can show all information or description about people who have that name...that information are take from "member_table"...
<tr>
<td>
<td>
<td><input type="text"........></td>
</td>
</td>
</tr>
<tr>
<td> //i want information show here
</td>
<tr>
what's code for it?

Well the answer would be in 3 part.
<tr>
<td> //i want information show here
</td>
<tr>
modify this to
<tr>
<td> <div id="divResult"></div></td>
<tr>
Now you need to write javascript
<script>
// Get the data from the text field
var txtName = document.getElementById("txtName").value;
// Assuming there is a Ajax Function
ajax(txtName);
//Call back function for ajax
function callBack()
{
if(ajaxObj.... )
{
document.getElementById("divResult").innerHTML = ajaxObj.responseText;
}
}
</script>
The third part is getting the required data from Mysql server from PHP.
<?php
$name = $_REQUEST['txtName'];
echo getDataFromMySQL($name);
?>

Related

How to pass TD id through POST via form

I have a small problem. I have this in my code:
<td id="def1s"></td>
<td id="def1r"></td>
<td id="def1g"></td>
<td id="def1m"></td>
where the id's are populated through AJAX when i change select (dropdown).
Now i want to pass the id's to database when i press Save Changes button on the form.
I figured out i can't pass id value's through POST, neither can i use "name=". How can i make it possible to send the value's given after changing select via POST to database?
EDIT
Thanks for the input so far, i tried some things, but i guess it's a bit more complicated...
in html i have this:
<select class="form-control" id="weapon" name="weapon">
<option value="<?= $general['weapongear']; ?>"><?= $general['weapongear']; ?></option>
<?php foreach($gearweapons as $gearweapon): ?>
<option value="<?= $gearweapon['ID']; ?>"><?= $gearweapon['gearname']; ?></option>
<?php endforeach; ?>
</select>
<table class="table table-dark table-striped">
<thead>
<tr>
<th></th>
<th>Siege</th>
<th>Ranged</th>
<th>Ground</th>
<th>Mount</th>
</tr>
</thead>
<tbody>
<tr>
<td>ATT</td>
<td id="att1s"></td>
<td id="att1r"></td>
<td id="att1g"></td>
<td id="att1m"></td>
</tr>
<tr>
<td>DEF</td>
<td id="def1s"></td>
<td id="def1r"></td>
<td id="def1g"></td>
<td id="def1m"></td>
</tr>
<tr>
<td>HP</td>
<td id="hp1s"></td>
<td id="hp1r"></td>
<td id="hp1g"></td>
<td id="hp1m"></td>
</tr>
</tbody>
</table>
Where all those id's are populated on select change:
$("#weapon").change(function() {
//get the selected value
var valweapon = this.value;
//make the ajax call
$.ajax({
url: '/ajax/gear_ajax.php',
type: 'POST',
data: {field : 'ID', value: valweapon},
success: function(data) {
document.getElementById("att1s").innerText = data['atts'];
document.getElementById("att1r").innerText = data['attr'];
document.getElementById("att1g").innerText = data['attg'];
document.getElementById("att1m").innerText = data['attm'];
document.getElementById("def1s").innerText = data['defs'];
document.getElementById("def1r").innerText = data['defr'];
document.getElementById("def1g").innerText = data['defg'];
document.getElementById("def1m").innerText = data['defm'];
document.getElementById("hp1s").innerText = data['hps'];
document.getElementById("hp1r").innerText = data['hpr'];
document.getElementById("hp1g").innerText = data['hpg'];
document.getElementById("hp1m").innerText = data['hpm'];
}
});
});
This is how the result looks like:
When i click submit button, all the values in the table should be update to database, regardless there is a value or it is NULL
There are many ways, but I am giving you the easiest one.
when you change select (dropdown), You need to pass the select box value plus COMMA SEPARATED STRING OF IDS
You can use json format and separate both in your ajax function. Thus in this way, assign the string to a existing form hidden value and when you will submit the form, you will get all the IDS

How to get selected product's price and show it on table?

so the requirement is to have a table which allows the user to create a new estimate online. I went as far as adding rows/ deleting them, having my DB's product list on the product field. But once I select the product, I would like the field 'Price' to pull up its price.
Here's the code I am currently using:
<INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
<TABLE id="dataTable" width="350px" border="1">
<TR>
<TD><INPUT type="checkbox" name="chk"/></TD>
<TD><INPUT type="text" name="txt"/></TD>
<TD>
<SELECT name="country" onchange="getPrice(this.value, this.closest('tr').rowIndex);">
<?php while($row = mysql_fetch_array($query)) {
echo '<option value="' .$row['nom'] . '">'.$row['nom'].'</option>'; }
?>
</SELECT>
</TD>
<TD><INPUT type="text" name="txt"/></TD>
</TR>
</TABLE>
Ok, so what I assume is that your javascript function getPrice(name, tablecell) should retrieve the price stored in your database and puts it's price-value into the given table cell.
Before I write out a possible solution, I would like to add: This solution will keep the values from the database in a client-side array. Thus visible for any user, reviewing the code of your page. This shouldn't be an issue if you only store non-critical information though.
// For testing purpose i filled in a mini-json, but in
// the PHP-example later this post you will find a short
// example how to fill this with PHP from your database
var prices = {
'test_prod_1' : 16.46,
'test_prod_2' : 21.55,
'test_prod_3' : 7.4
};
function getPrice( prodID, tableCell )
{
if (typeof prices[prodID] !== 'undefined')
tableCell.innerHTML = '€' + prices[prodID]; // Get the price from the pre-loaded price information
else
tableCell.innerHTML = '?';
}
<input type="button" value="click me" onClick="javascript:getPrice('test_prod_2', document.getElementById('test_cell'));">
<table border=1 cellspacing=0 cellpadding=5>
<tr>
<td>Product name</td>
<td>price</td>
</tr>
<tr>
<td>test</td>
<td id="test_cell"></td>
</tr>
</table>
And then with PHP You would be able to create this price list dynamically. But, remember that the data is visible client side, so this example will only select the price and name/id data. Make sure to edit the variable names to the ones you use.
<script type="text/javascript">
var prices = <?php
$js_pricelist = array();
// Retireve the information from the server's database. Assume that $result is a result set in an ASSOC
foreach( $result as $row )
$js_pricelist[ $row['prodID'] ] = $row['prodPrice'];
echo JSON_Encode( $js_pricelist );
?>
</script>
Please check the last script as I haven't tested it yet, and is meant more to give you an idea of the possibilities
Conclusion: The main idea is, that once you load the page, you assemble a javascript object containing all price data (Using PHP). You echo this object to a javascript block, and make a function that reads from this newly created array/object to retrieve the price that corresponds to the product_id.

html add item and show lists with using php

I am new in HTML
i want to make a user list web page. The page reads user.txt and show then left column of the tabel.
And new items in which New User column will be added to user.txt list
Instead of get/post http methos i am trying to use 2 AJAX methods to communicate the server side.
After sending url with AJAX i will call php scripts on the server side
I think first AJAX method for adding is below
XMLHttpRequestObject.open("GET", dataSource);
However. I coulnt find the second. And i dont know how to implement
Here is my code
<!DOCTYPE html>
<SCRIPT language="javascript">
function add(nm, ml) { }
function read(nam,mail) { }
</SCRIPT>
<html>
<body>
<table border = "1">
<thead>
<tbody>
<tr>
<th>Registered Users</th>
<th>New User</th>
</tr>
<tr>
<td></br></td>
<td>
<p><label>Name:
<input name = "name" type = "text">
<p><label>Email:
<input name = "email" type = "text">
</td>
</tr>
<tr>
<td>
<p></p>
<button onclick="read()">Read users list</button>
</td>
<td>
<p></p>
<button onclick="add(name,email)">Add user to list</button>
<p id="demo2"></p>
</td>
</tr>
</tbody>
</thead>
</table>
</body>
</html>

HTML form to update Mysql with PHP (and HTML)

I've been trying to develop a real estate page where people can add listings. I am new to the world of php mysql. I have been over this problem for over a day and can't figure out where the problem is.
I have a form where people can add data. That's good and working. Now I am starting to have a place where people can add / delete / update their info. I am trying to build this step by step.
This is where a user could pull the information. My problem is with the piece of the code:
edit_form.php?idBAR=$row[id].
Full code below.
<table>
<tr>
<td align="center">EDIT DATA</td>
</tr>
<tr>
<td>
<table border="1">
<?php
include"configS_OH.php";//database connection
$order = "SELECT * FROM braaasil_brokerstour.property";
$result = mysql_query($order);
while ($row=mysql_fetch_array($result)){
echo ("<tr><td>$row[id]</td>");
echo ("<td>$row[address]</td>");
echo ("<td>$row[day]</td>");
echo ("<td>$row[hours]</td>");
echo ("<td>Edit</td></tr>");
}
?>
</table>
</td>
</tr>
</table>
Then this tutorial try to pass id through the address bar (I don't know much about php to actually say much)
It tries to upload the data into a new form where a person could edit info.
But I can't load the data into the new form. If I use where id=7, I get the info into the form. But this method of passing the info in the address bar like ?idBAR=8... and then try to catch it in the other code (where id=$idBAR), is not working.
Here is the code:
<table border=1>
<tr>
<td align=center>Form Edit Employees Data</td>
</tr>
<tr>
<td>
<table>
<?php
include "configS_OH.php";//database connection
print $database;
$order = "SELECT * FROM braaasil_brokerstour.property
WHERE id='$idBAR'";
print $idBAR;
$result = mysql_query($order) or die( mysql_error() );
$row = mysql_fetch_array($result);
?>
<form method="post" action="edit_data.php">
<input type="hidden" name="idBAR" value="<?php echo "$row[id]"?>">
<tr>
<td>Address</td>
<td>
<input type="text" name="address"
size="20" value="<?php echo "$row[address]"?>">
</td>
</tr>
<tr>
<td>Date</td>
<td>
<input type="text" name="day" size="40"
value="<?php echo "$row[day]"?>">
</td>
</tr>
<tr>
<td>Time</td>
<td>
<input type="text" name="time" size="40"
value="<?php echo "$row[hours]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
I tried an tried and tried..
Thank you for your time in advance.
WHERE id='$idBAR'
You haven't assigned $idBAR any value. You need to read it from the $_GET array first:
$idBAR = $_GET['idBAR'];
You should, of course, check that this value exists first, and is acceptable.
I don't see anywhere you have actually used the GET data, just the reference name which is used in GET.
If you first query is working and is getting the $row['id'] value ok - you can verify this when you go to edit_form.php, in your browser URL bar at the top, does it say this:
edit_form.php?idBAR=7
(or whatever number should be there)
If so, then you just need to use the PHP GET. Your data is stored in $_GET[], and in this case, the reference name is idBAR. So your id from your previous page query is sent through the link into your URL, and on your edit_form.php page, you'd use that data as:
$_GET['idBAR']
You can use that, but personally I assign the data to a variable, such as:
$strGetId = $_GET['idBAR'];
Then you can use $strGetId throughout your code.
Also, check things like isset(), empty() etc, just so you know you are working with A) something is actually there, and B) it's not empty etc
if you are putting a variable directly in a string without concatenating, it can't be an array variable; you must concatenate those you also need to surr. so this
echo ("<td>Edit</td></tr>");
should be this
echo ("<td>Edit</td></tr>");
also, it looks like your form is sending data with POST. When you pass form data in the url string after the question mark, that is passing with get.
so...in your form where you want to use that variable, you set it up like this
$idBAR=$_GET['idBAR']; //to get the variable if it was part of the URL
$idBAR=$_POST['idBAR']; //if it was sent with post, as is the case with your form
also, request contains both get and post, so
$idBAR=$_REQUEST['idBAR'];
will work in either case.
The problem is the $row[id] is seen as text just like everything else. You want the value of $row[id]. Instead of
echo ("<td>Edit</td></tr>");
try
echo ("<td>Edit</td></tr>");

connection textfield and html table with database

dear all..i have a textfield
<tr>
<td>
<td><input type="text" id="model_name"></td>
</td>
</tr>
and a cell
<tr>
<td><div id="value">//i want data show here after fill textfield</div>
</td>
</tr>
beside that, i've a table "settingdata" in database it consist of 2 field:itemdata and remark..
itemdata's value are "UD" and remark's value are "FM=87.5-108.0MHZ"...
what must i do if i want after type model name "car01UD" at textfield inside
<div id="value"></div>
can show "FM=87.5-108.0mhz"...
if you want "0103" + value of itemdata then do following
<input type="text" id="mod" value="0103<?PHP echo $itemdata ?>">
Looks like you are trying to do basic Ajax functionality. Consider reading some Ajax tutorials to get an idea how to do this.

Categories