Php show users data from mysql with dropdown list - php

i want to display users data in a table with the dropdown list , the first option shows all the users but when i click a name it still shows all users, i think i have some trouble in my ajax script because it deosn't seem to work
this is the page where i display data :
<?php
//load_data_select.php
$connect = mysqli_connect("localhost", "root", "ntr-ktb123", "absence");
function fill_emp($connect)
{
$output = '';
$sql = "SELECT * FROM employés";
$result = mysqli_query($connect, $sql);
while($row = mysqli_fetch_array($result))
{
$output = $output."'<option value="'.$row["IdEmp"].'">'.$row["NomEmp"].'</option>'";
}
return $output;
}
function fill_Abs($connect)
{
$output = '';
$sql = "SELECT NomEmp,PrénomEmp,DateD,DateF,CauseAbs,justifié
FROM absence.absences
WHERE
MONTH(DateF) = MONTH(NOW())
AND
YEAR(DateF) = YEAR(NOW());";
$result = mysqli_query($connect, $sql);
echo "<table>
<tr>
<th>NomEmp</th>
<th>PrénomEmp</th>
<th>DateD</th>
<th>DateF</th>
<th>CauseAbs</th>
<th>justifié<th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['NomEmp'] . "</td>";
echo "<td>" . $row['PrénomEmp'] . "</td>";
echo "<td>" . $row['DateD'] . "</td>";
echo "<td>" . $row['DateF'] . "</td>";
echo "<td>" . $row['CauseAbs'] . "</td>";
echo "<td>" . $row['justifié'] . "</td>";
echo "</tr>";
}
$output="</table>";
return $output;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Webslesson Tutorial | Multiple Image Upload</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
/>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js">
</script>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js">
</script>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
<script>
$(document).ready(function(){
$('#nom').change(function(){
var NomEmp = $(this).val();
$.ajax({
url:"usr.php",
method:"POST",
data:{NomEmp:NomEmp},
success:function(data){
$('#show_Abs').html(data);
}
});
});
});
</script>
</head>
<body>
<br /><br />
<div class="container">
<h3>
<label for="nom">Selectionnez le nom de l'employé </label>
</br></br>
<select name="nom" id="nom">
<option value="">Tout les employés</option>
<?php echo fill_emp($connect); ?>
</select>
<br /><br /> <br />
<div class="row" id="show_Abs">
<?php echo fill_Abs($connect);?>
</div>
</h3>
</div>
</body>
</html>
and this is the usr.php :
<?php
//load_data.php
$connect = mysqli_connect("localhost", "root", "ntr-ktb123", "absence");
$output = '';
if(isset($_POST["NomEmp"]))
{
if($_POST["NomEmp"] != '')
{
$sql = "SELECT NomEmp,PrénomEmp,DateD,DateF,CauseAbs,justifié
FROM absence.absences
WHERE
MONTH(DateF) = MONTH(NOW())
AND
YEAR(DateF) = YEAR(NOW()) WHERE NomEmp = '".$_POST["NomEmp"]."'";
}
else
{
$sql = "SELECT NomEmp,PrénomEmp,DateD,DateF,CauseAbs,justifié
FROM absence.absences
WHERE
MONTH(DateF) = MONTH(NOW())
AND
YEAR(DateF) = YEAR(NOW());";
}
$result = mysqli_query($connect, $sql);
$output="<table>
<tr>
<th>NomEmp</th>
<th>PrénomEmp</th>
<th>DateD</th>
<th>DateF</th>
<th>CauseAbs</th>
<th>justifié<th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['NomEmp'] . "</td>";
echo "<td>" . $row['PrénomEmp'] . "</td>";
echo "<td>" . $row['DateD'] . "</td>";
echo "<td>" . $row['DateF'] . "</td>";
echo "<td>" . $row['CauseAbs'] . "</td>";
echo "<td>" . $row['justifié'] . "</td>";
echo "</tr>";
}
echo $output;
}
?>
can anyone help me to find the problem in this ? any help would be appreciated.
Thanks.

We could use a little more info to help with this, but I'll try to get the ball rolling.
I would guess that $_POST["NomEmp"] in usr.php is === "" so the else is running, which shows the entire table again.
I can't tell what you are setting the "value" attribute to in the fill_emp function. What is the value of $row[1] in that function?

Just change the ajax call like mentioned below :
$(document).ready(function(){
NomEmp = "";
$.ajax({
url:"usr.php",
method:"POST",
data:{NomEmp:NomEmp},
success:function(data){
$('#show_Abs').html(data);
}
});
$('#nom').change(function(){
NomEmp = $(this).val();
$.ajax({
url:"usr.php",
method:"POST",
data:{NomEmp:NomEmp},
success:function(data){
$('#show_Abs').html(data);
}
});
});
});
Also in your html cannot able to find a tag having id show_Abs. So just modify the div into
<div class="row" id="show_Abs">
</div>
Now I think the php function <?php echo fill_Abs($connect);?> is not necessary.
When page loads the first time, ajax call will be generated and on changing the select tag call will be generated with passing the selected parameters getting appropriate results.

Related

PHP file containing checkboxes in a table that fetches data from a database?

I want a checkbox for each query that way when the table is populated with data from the db, there is also a checkbox to confirm that booking for each query result.
I also want to know how to create a script that once a single checkbox has been selected,I click on submit and it takes me to another page that displays values (route_no,to_city,from_city and price) based on the checkbox selected and route_no corresponding to that checkbox selected. route_no is auto_incrementing and is a primary key(values of route_no range from 0-49).
this is my html form
<html>
<head>
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","display.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<form>
<select name="to_city" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="Sydney">Sydney</option>
<option value="Brisbane">Brisbane</option>
<option value="Adelaide">Adelaide</option>
<option value="Newcastle">Newcastle</option>
</select>
</form>
<br>
</body>
</html>
and below is my php file, which has text that shows what I want to acheive. The text has been commented out.
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<?php
$q = strval($_GET['q']);
$con = mysqli_connect('localhost','root','','mydb');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"flights");
$sql="SELECT * FROM flights WHERE to_city = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>Route_no</th>
<th>to_city</th>
<th>from_city</th>
<th>price</th>
<th>Confirm</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['route_no'] . "</td>";
echo "<td>" . $row['to_city'] . "</td>";
echo "<td>" . $row['from_city'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
/// I want a checkbox here for each query that way when the table is populated with data from the db, there is also a checkbox to confirm that booking for each query result.
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
I'll edit the body section of your php code. Try and see
<body>
<?php
$q = strval($_GET['q']);
$con = mysqli_connect('localhost','root','','mydb');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"flights");
$sql="SELECT * FROM flights WHERE to_city = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>Route_no</th>
<th>to_city</th>
<th>from_city</th>
<th>price</th>
<th>Confirm</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['route_no'] . "</td>";
echo "<td>" . $row['to_city'] . "</td>";
echo "<td>" . $row['from_city'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "<td><input type=\"checkbox\" name=\"example\" class=\"radio\" value=\"example\"></td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</body>
here is the jQuery part:
$("input:checkbox").change(function(){
var group = ":checkbox[name='"+ $(this).attr("name") + "']";
if($(this).is(':checked')){
$(group).not($(this)).attr("checked",false);
}
});
Well you've already got annotations at the right spot:
echo "<form>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['route_no'] . "</td>";
echo "<td>" . $row['to_city'] . "</td>";
echo "<td>" . $row['from_city'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "<td><input type='checkbox' name='checkbox_id' value='" . $variable_that_has_id . "'> </td>";
echo "</tr>";
}
echo "</form>";
of course you'll have to replace the $variable_that_has_id with whatever $row[] correlates with the id in your database.
After that you can create a submit button, then use the form to post data to the same page(or a different one) and you can use the $_POST variable to grab whatever values were checked and submitted with the form.
I highly suggest getting familiar with creating forms in html and usage of $_POST since it is relevant to what you're doing.
if you want to allow the user to only select one option change the input type to "radio"

checkbox in table in php

I want to have a table that contains words and their meaning from database, in another column i want to have checkbox for each row, that user will check them and show what words he/she know.
i have two question in this case:
1- how can i hide the meaning in the first and after clicking in show meaning visible them?
2- how can i set checkboxes?
i have this code until now but it doesn't work
please help me if you can
<script type="text/javascript">
function ShowMeanings(){
document.getElementsByClassName('hiding').item(0).style.visiblility = 'visible';
}
</script>
<?php
$con = mysql_connect("localhost", "root", "")
or die(mysql_error());
if (!$con) {
die('Could not connect to MySQL: ' . mysql_error());
}
mysql_select_db("project", $con)
or die(mysql_error());
$result = mysql_query("select * from words");
echo "<table border='1'>
<tr>
<th>word</th>
<th>meaning</th>
<th>check</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['word'] . "</td>";
echo "<td>";
echo "<div";
echo "class='hiding' style='visibility:hidden'>" . $row['meaninig'];
echo "</div>";
echo "</td>";
echo "<td>";
echo "<input";
echo "type= 'checkbox' name = 'checkbox' id = 'checkbox' value = '' />";
echo "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</div>
<button onclick="ShowMeanings()">showmeaning</button>
getElementByClassName is an inexistant function. You mean getElementsByClassName, which will however return a list of the elements, so you need to select one.
document.getElementsByClassName('hiding').item(0).style.visibility = 'visible';
For hide a suggestion:
echo "class='hiding' style='display:none'>" . $row['meaninig'];
To show the meaning:
//for Jquery
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
function ShowMeanings(){
$('.hiding').shoW();
}
</script>
Or
//for plain old javascript
<script type="text/javascript">
function ShowMeanings(){
document.getElementsByClassName('hiding').style.visibility = 'visible';
}
</script>
Your code Edited:
<html><head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
function ShowMeanings(){
$('.hiding').shoW();
}
</script>
</head>
<body>
<?php
$con = mysql_connect("localhost", "root", "")
or die(mysql_error());
if (!$con) {
die('Could not connect to MySQL: ' . mysql_error());
}
mysql_select_db("project", $con)
or die(mysql_error());
$result = mysql_query("select * from words");
echo "<table border='1'>
<tr>
<th>word</th>
<th>meaning</th>
<th>check</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['word'] . "</td>";
echo "<td>";
echo "<div";
echo "class='hiding' style='display:none'>" . $row['meaninig'];
echo "</div>";
echo "</td>";
echo "<td>";
echo "<input";
echo "type= 'checkbox' name = 'checkbox' id = 'checkbox' value = '' />";
echo "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</div>
<button onclick="ShowMeanings()">showmeaning</button>
</body>

Deleting Checked box data in Mysql Table from form

I am working on an inventory program and I need help on the following:
I have a table that works through selecting data from my Database and showing this in a table.
I now need to make it possible for a user to be able to delete bad/faulty records from the form ( Ofcourse u don't want to everytime have to go in the database itself to remove a record, would be stupid)
My code:
<div id="artikel-container">
<table class="table 1">
<thead>
<title>Inventory Grid.html</title>
<meta charset = "UTF-8" />
<style type = "text/css">
table, td, th {
border: 1px solid black;
}
</style>
</thead>
<tbody>
<?php
$con = mysqli_connect("localhost", "root", "admin", "inventarisdb");
// Check connection
if ( mysqli_connect_errno() ) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query( $con, "SELECT * FROM BCD" );
echo "<table border='0'>
<tr>
<th>Categorie</th>
<th>SerieNummer</th>
<th>MacAdress</th>
<th>ProductCode</th>
<th>Prijs</th>
<th>RekNummer</th>
<th>PaletNummer</th>
<th>Hoeveelheid</th>
<th>Aantekeningen/th>
</tr>";
while( $row = mysqli_fetch_array( $result ) ) {
echo "<tr>";
echo "<td>" . $row['Categorie'] . "</td>";
echo "<td>" . $row['SerieNummer'] . "</td>";
echo "<td>" . $row['MacAdress'] . "</td>";
echo "<td>" . $row['ProductCode'] . "</td>";
echo "<td>" . $row['Prijs'] . "</td>";
echo "<td>" . $row['RekNummer'] . "</td>";
echo "<td>" . $row['PaletNummer'] . "</td>";
echo "<td>" . $row['Hoeveelheid'] . "</td>";
echo "<td>" . $row['Aantekeningen'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</article>
</fieldset>
</tbody>
This code works perfectly!
What i want to achieve is to select Records from this table with a checkbos and delete them by clicking on a delete button in the bottom of the page programmed like this:
<Input type="submit" id="submit" name="submit" value="Verwijderen" />
Or at least with this principle!
(This is the second ever application I wrote, 1st was a webpage, and I have no idea how to research this. I keep finding questions and posts that are just not what i need :S Hope U can help me )
I suggest you to use jQuery ajax so you will be able to delete entry one by one without page reload.
At first include jQuery library in HTML HEADER and the Javascript script file
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="script.js"></script>
script.js:
$(document).ready(function() {
$(".delete").click(function(event) {
var entryid = $(this).closest('tr').find('.entryid').val();
alert('This entry will be deleted: ' + entryid); // this will alert you the value what you get. After finisgin to get correct value you can delete this
$.ajax({
type: "GET",
url: "delete.php",
data: "id=" + entryid
});
$(this).closest('tr').remove();
});
});
in MySQL database must be uniqe ID for every entry named 'id'
Grid.html:
echo "<td>" . $row['Aantekeningen'] . "</td>";
echo '<td><input type="hidden" class="entryid" name="id" value='.$row['id'].' />delete</td>';
delete.php:
// connect to database
$id = $_GET['id'];
$sql="DELETE FROM BCD WHERE id='$id'";
First of all you need to wrap the table into a form
<div id="artikel-container">
<form name="form1" method="post" action="...">
<table class="table 1">
...
echo "</table></form>";
mysqli_close($con);
Next you need the checkboxs on the form $row['ID'] is the primary key of the table
echo "<td>" . $row['Aantekeningen'] . "</td>";
echo "<td><input type='checkbox' name='del[]' value='".$row['ID'] . "></td>";
echo "</tr>";
In the php file called in the form's action attribute:
<?php
if( isset( $_POST['del'] ) {
$del = $_POST['del'];
for(x=0; x<count(del); x++ ) {
$sql = 'DELETE FROM BCD WHERE ID='.$del[$x];
//---execuste the query
}
}
?>

Calling JavaScript from within PHP logic error

I am printing out a number of rows from my database. Each row contains one td which contains which id is the respective row number(row numbers start at 1).
As each row is echoed, I update the rows with addresses using javascript .appendChild(), addresses whose co-ordinates have been called from the db.
The first 5 rows co-ordinates have been correctly converted into addresses, and the remaining rows have the correct co-ordinates called from the db(I know because I checked the source) however the address being entered in the row is always the value of the last row on the db.
Please note that the co-ordinates are being converted to addresses using google maps api.
if ( mysql_num_rows( $result ) > 0 ){
$i = 1;
while($row = mysql_fetch_array($result)){
echo "<tr>";
?>
<script>
initialize();
var counter = 1;
function initialize() {
var geocoder;
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(<?php echo $row['latitude'] ?>,<?php echo $row['longitude'] ?>);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
var txt = results[0].formatted_address;
var newtext = document.createTextNode(txt);
document.getElementById("address" + counter).appendChild(newtext);
counter++;
} else {
alert('No results found');
}
} else {
//alert('Geocoder failed due to: ' + status);
}
});
}
setInterval(convert, 2);
function convert() {
initialize();
}
</script>
<?php
echo "<td id='address" . $i . "'></td>";
$i++;
}
Solution
After a bit of thinking, and a lot of googling, I solved it! Entire code below for anyone else that might stumble on this!
<?php
// security check
$account_type = $_COOKIE["account_type"];
if($account_type != "canvass_leader" && $account_type != "leader" && $account_type != "canvasser"){
header("location:login.php");
}
$username_cookie2 = $_COOKIE["username_cookie"];
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles/style.css"/>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<title>Canvassing Data</title>
<style type="text/css">
#header #welcome #para{
margin-top: -84px;
}
</style>
<script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
<script>
function setUp() {
window.counter = 1;
setInterval(initialize, 700);
}
function initialize() {
var geocoder;
geocoder = new google.maps.Geocoder();
var lat = document.getElementById("lat" + counter);
var lng = document.getElementById("lng" + counter);
//alert(lat.innerHTML);
//alert(lng.innerHTML);
var latlng = new google.maps.LatLng(lat.innerHTML,lng.innerHTML);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
var txt = results[0].formatted_address;
var addressValue = document.createTextNode(txt);
$('#lat' + counter).remove();
$('#lng' + counter).remove();
var element = "#address" + counter;
$(element).append(addressValue)
counter++;
} else {
alert('No results found');
}
} else {
//alert('Geocoder failed due to: ' + status);
}
});
}
</script>
</head>
<body onload="setUp()" >
<div id="wrapper">
<?php
include('header.php');
// connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get party cookie
$party = $_COOKIE["party"];
// set table name
$tbl_name = "checklist_" . $party;
?>
<div id='info_bubble'>From this page you can view, search and export all collected canvassing data.</div>
<?php if($account_type == "canvass_leader") { ?>
<div style="text-align: center;">
<form id="" method="post" action="" style="margin: 20px 0 30px 0;">
<h3>Search Canvassing Data</h3>
<fieldset id="inputs" >
<input style="width: 270px;" name="search_name" type="text" placeholder="Search by canvasser name.." >
<input style="width: 270px;" name="search_reception" type="text" placeholder="Search by reception at door.." >
</fieldset>
<fieldset id="actions" class="button button-blue">
<span><input type="submit" id="submit" name="search" value="Search Data"></span>
</fieldset>
</form>
</div>
<?php } ?>
<?php
if(isset($_POST['search'])) {
$search_name = $_POST['search_name'];
$search_reception = $_POST['search_reception'];
if(strlen($search_name)) {
$sql = "SELECT * FROM $tbl_name WHERE canvasser = '$search_name'";
$result = mysql_query($sql);
}
if(strlen($search_reception)) {
$sql = "SELECT * FROM $tbl_name WHERE reception_at_door = '$search_reception'";
$result = mysql_query($sql);
}
}
else{
if($account_type == "canvass_leader") {
$sql = "SELECT * FROM $tbl_name WHERE creator = '$username_cookie2'";
$result = mysql_query($sql);
}
else { // account_type = Leader
$sql = "SELECT * FROM $tbl_name";
$result = mysql_query($sql);
}
}
// display table data
echo "<div id='content'>
<table class='bordered' border='1'>
<tr>
<th>Address</th>
<th>House Number</th>
<th>Registered to Vote</th>
<th>Visited by Candidate</th>
<th>Leafleted</th>
<th>Canvassed</th>
<th>Reception at Door</th>
<th>Canvasser</th>
</tr>";
if ( mysql_num_rows( $result ) > 0 ){
//$num_rows = mysql_num_rows($result);
//echo "$num_rows Rows\n";
$i = 1;
while($row = mysql_fetch_array($result)){
echo "<tr>";
?>
<?php
//echo "<td id='address" . $i . "'></td>";
//echo "<td id='address" . $i . "'>" . $row['latitude'] . " ## " . $row['longitude'] . "</td>";
//echo "<td id='address" . $i . "'>" . $row['latitude'] . " ## " . $row['longitude'] . "</td>";
echo "<td id='address" . $i . "'><p id='lat" . $i . "'>" . $row['latitude'] . "</p><p id='lng" . $i . "'>" . $row['longitude'] . "</p></td>";
// only set co-ordiantes first, then convert them to address by getElementById and appendChild when dom is ready in js in head of page
echo "<td>" . $row['house_number'] . "</td>";
echo "<td>" . $row['registered_to_vote'] . "</td>";
echo "<td>" . $row['visited_by_candidate'] . "</td>";
echo "<td>" . $row['leafleted'] . "</td>";
echo "<td>" . $row['canvassed'] . "</td>";
echo "<td>" . $row['reception_at_door'] . "</td>";
echo "<td>" . $row['canvasser'] . "</td>";
echo "</tr>";
$i++;
}
}
echo "</table>";
if( $account_type == "canvass_leader" || $account_type == "leader"){
echo '<form style="margin-top: 10px;" action="dash_data_canvassing_export.php">';
echo '<fieldset id="actions" class="button button-blue"><span><input type="submit" value="Export Data" id="submit" name="submit"></span></fieldset>';
echo '</form></div>';
}
include('footer.php');
?>
</div>
</body>
</html>

click row to fill textboxes in php - array vs ajax

I have a table coded in php which pulls in data from mysql database and displays it in a html table . Now when i click on a row I need certain textboxes to be filled.
What is the best approach for this: is it using an array or ajax,html and php,
<?php
$default = "<img src='http://localhost/on.png' width='24' height='24'/>";
$default1 = "<img src='http://localhost/of.png' width='24' height='24'/>";
$con = mysql_connect("*****","******","******");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db ("*****",$con);
$sql= "select act.*
from audit_activity as act
inner join (
select user_id, max(timestamp) as max_ts
from activity
group by user_id) as a on act.user_id=a.user_id and act.timestamp=a.max_ts";
$mydata = mysql_query($sql,$con);
echo "<table id='tfhover',table border=0>
<tr>
<th>Users</th>
<th>Status<th>
</tr>";
while($record = mysql_fetch_array($mydata)){
echo "<tr>";
echo "<td>" . $record['user_id'] . "</td>";
if (strtolower(trim($record['activity']))!=strtolower('LOGIN')){
echo "<td>" . $default1 . "</td>";
}else{
echo "<td>" . $default . "</td>";
}
echo "</tr>";
}
echo "</table>";
;
mysql_close($con);
?>
<html>
<script type="text/javascript">
window.onload=function(){
var tfrow = document.getElementById('tfhover').rows.length;
var tbRow=[];
for (var i=1;i<tfrow;i++) {
tbRow[i]=document.getElementById('tfhover').rows[i];
tbRow[i].onmouseover = function(){
this.style.backgroundColor = '#ffffff';
};
tbRow[i].onmouseout = function() {
this.style.backgroundColor = '#d4e3e5';
};
}
};
</script>
<head>
</head>
<body>
Total exams taken : <br>
<input type="text" name="fname"/>
</body>
</html>

Categories