i need help. i have a table that i need to view the data of the user that already doing report. when the technician update the form, user can know who is the responsible person for their report. upon update the technician will send the id to the database but the problem is the user will see the id when they check the report. i need to change the id to the technician name.
<tr bgcolor="#00aeef">
<td>Tarikh</td>
<td>Staff ID</td>
<td>Kerosakan</td>
<td>Nyatakan</td>
<td>Maklumat Kerosakan</td>
<td>Lokasi Kerosakan</td>
<td>Nama Pegawai</td>
<td>Status</td>
<td>Catatan</td>
</tr>
<?php include('../dbcon.php');
$username=$_SESSION['username'];
$username_view=$_SESSION['username_view'];
$qry=mysql_query("SELECT * FROM aduan_form where staff_id='$username' ORDER BY tarikh DESC") or die(mysql_error());
?>
<?php while ($row_view = mysql_fetch_array($qry)){ ?>
<?php if ($totalRows_view > 0) { // Show if recordset not empty ?>
<?php } // Show if recordset not empty ?>
<tr>
<td><?php echo $row_view['tarikh']; ?></td>
<td><?php echo $row_view['staff_id']; ?></td>
<td><?php echo $row_view['kerosakan']; ?></td>
<td><?php echo $row_view['nyatakan']; ?></td>
<td><?php echo $row_view['m_kerosakan']; ?></td>
<td><?php echo $row_view['tempat_rosak']; ?></td>
<td><?php echo $row_view['nama_pegawai']; ?></td>
<td><?php echo $row_view['status']; ?></td>
<td><?php echo $row_view['catatan']; ?></td>
<?php } while ($row_view = mysql_fetch_assoc($view)); ?></tr>
</table>
here is my current code.
i do try to put some code that will allow the id to change to the name but it view the same name and it is even in the table that is still not been update.
<?php include('../dbcon.php');
$username=$_SESSION['username'];
$username_view=$_SESSION['username_view'];
$qry1=mysql_query("SELECT * FROM login,aduan_form where aduan_form.nama_pegawai=login.username ORDER BY aduan_form.tarikh DESC") or die(mysql_error());
?>
<?php while ($row_view1 = mysql_fetch_array($qry1)){ ?>
how should i do to make it right? i need the table to view the right technician name based on the right id and also display the name only in the table that already been update.
Hope I got your database schema right. So you can query like:
$qry1=mysql_query("
SELECT aduan_form.*, login.username
FROM aduan_form
LEFT JOIN login
ON login.id = aduan_form.staff_id
WHERE aduan_form.nama_pegawai=login.username
ORDER BY aduan_form.tarikh DESC")
or die(mysql_error());
and change your html output to something like:
...
<td><?php echo $row_view['tarikh']; ?></td>
<td><?php echo $row_view['username']; ?></td>
<td><?php echo $row_view['kerosakan']; ?></td>
...
Related
<?php if($result["staff_follow"]== 'By Party'&& $result["Status"]== 'PENDING'): ?> style="background-color:#E99E3E;
the below feiled is not working.
"onmouseover="this.bgColor='litegreen'" onmouseout="this.bgColor='#E99E3E'"
<?php elseif($result["Status"]== 'PENDING'): ?>style= "background-color:#DB7093; "
<?php endif; ?> >
<!-- <td><?php echo $result["Roll_No"];?></td> -->
<td style="text-align: center;"><?php echo $counter ;?></td>
<td><?php echo $result["Document_Name"];?></td>
<td><?php echo $result["Document_Num"];?></td>
<td><?php echo $result["Extent"];?></td>
<td><?php echo $result["Status"];?></td>
<td><?php echo $result["Document_App_Det"];?></td>
<td><?php echo $result["staff_follow"];?></td>
Try again with this.bgColor='LightGreen'.
The named colors can be found here:
https://htmlcolorcodes.com/color-names/
The below code is connected to a local database that holds customer information. First, the page is supposed to display the customer name and country, but should display more information for that particular customer once the name is clicked.
The problem with this code below is that it will only always display the first customers information, no matter which name is clicked. Can anyone see where I might be going wrong? Do I need to create an ID for each button (customer name)? Bare in mind that there are a lot of customers in the database and I feel that an ID for each would be very difficult to implement, especially if the database gets modified.
<DOCTYPE html!>
<html>
<head>
<link rel="stylesheet" type="text/css" href="a3.css">
</head>
<body>
<div class="nav">
<?php include 'nav.php';
?>
</div>
<?php include 'dbconfig.php';
$sql ='SELECT * FROM `customers` ORDER BY `customers`.`country` ASC';
$q = $conn->query($sql);
$q->setFetchMode(PDO::FETCH_ASSOC);
?>
<div class = "main">
<table>
<?php while ($r = $q->fetch()): ?>
<tr>
<td><button onclick = "showCustomer();"/><?php echo ($r['customerName'])?></td>
<td><?php echo ($r['country'])?></td>
</tr>
<tr id ="extra" style="display:none">
<td><?php echo ($r['customerNumber'])?></td>
<td><?php echo ($r['contactLastName'])?></td>
<td ><?php echo ($r['contactFirstName'])?></td>
<td><?php echo ($r['phone'])?></td>
<td><?php echo ($r['addressLine1'])?></td>
<td><?php echo ($r['addressLine2'])?></td>
<td><?php echo ($r['city'])?></td>
<td><?php echo ($r['state'])?></td>
<td><?php echo ($r['postalCode'])?></td>
<td><?php echo ($r['salesRepEmployeeNumber'])?> </td>
<td><?php echo ($r['creditLimit'])?></td>
</tr>
<?php endwhile; ?>
</table>
</div>
<div class="foot">
<?php include 'foot.php'; ?>
</div>
<script>
function showCustomer() {
var showForm=document.getElementById('extra');
if (showForm.style.display="none") {
showForm.style.display ="";
alert('ok');
console.log(showForm);
}
else if (showForm.style.display=""){
showForm.style.display ="none";
}
}
</script>
</body>
</html>
</DOCTYPE>
All your <tr> have the same id="extra". As suggested, you need a different "id" for each of them, this is how : I created a variable $i (line 18), that is increased right after the while (line 20), inserted as parameter in the call for showCustomer (line 23), inserted at the end of the id "extra" (line 27), finally, on the bottom, where function showCustomer is declared, the parameter "index" is inserted at the end of the id "extra".
<DOCTYPE html!>
<html>
<head>
<link rel="stylesheet" type="text/css" href="a3.css">
</head>
<body>
<div class="nav">
<?php include 'nav.php';
?>
</div>
<?php include 'dbconfig.php';
$sql ='SELECT * FROM `customers` ORDER BY `customers`.`country` ASC';
$q = $conn->query($sql);
$q->setFetchMode(PDO::FETCH_ASSOC);
?>
<div class = "main">
<table>
<?php $i = 0;
while ($r = $q->fetch()):
$i++; // UNIQUE INDEX FOR EACH CUSTOMER.
?>
<tr>
<td><button onclick = "showCustomer('<?php echo $i;?>');"/>
<?php echo ($r['customerName'])?></td>
<td><?php echo ($r['country'])?></td>
</tr>
<tr id ="extra<?php echo $i;?>" style="display:none">
<td><?php echo ($r['customerNumber'])?></td>
<td><?php echo ($r['contactLastName'])?></td>
<td ><?php echo ($r['contactFirstName'])?></td>
<td><?php echo ($r['phone'])?></td>
<td><?php echo ($r['addressLine1'])?></td>
<td><?php echo ($r['addressLine2'])?></td>
<td><?php echo ($r['city'])?></td>
<td><?php echo ($r['state'])?></td>
<td><?php echo ($r['postalCode'])?></td>
<td><?php echo ($r['salesRepEmployeeNumber'])?> </td>
<td><?php echo ($r['creditLimit'])?></td>
</tr>
<?php endwhile; ?>
</table>
</div>
<div class="foot">
<?php include 'foot.php'; ?>
</div>
<script>
function showCustomer( index ) { // UNIQUE INDEX AS PARAMETER.
var showForm=document.getElementById('extra' + index); // USING INDEX.
if (showForm.style.display="none") {
showForm.style.display ="";
alert('ok');
console.log(showForm);
}
else if (showForm.style.display=""){
showForm.style.display ="none";
}
}
</script>
</body>
</html>
</DOCTYPE>
i have a trouble with the datatables there.
I trying to add a datatables with responsive as the image
It's ok when i put it as a separate file but when i add the data from my database, i can not press on the plus icon to show detail about the member as the image
i just change the data and i don't know why it doesn't work.
Can you help?
This is my code: (i did close php tag for the first open php but i dont know why i can not post it on here)
<?php
$stt= 1;
$sql= "SELECT * from users ORDER BY level DESC";
//thuc hien cau lenh voi bien conn lay tu file connection.php
$query= mysqli_query($conn, $sql);
while ($data=mysqli_fetch_array($query)){
<tr>
<th scope="row"><?php echo $stt++?></th>
<td><?php echo $data["firstname"]?></td>
<td><?php echo $data["lastname"]?></td>
<td><?php echo $data["username"]?></td>
<td><?php echo $data["email"]?></td>
<td><?php echo $data["phone"]?></td>
<td>
<?php
if($data["level"] == 1){
echo "Administrator";
}else{
echo "Member";
}
?>
</td>
<td>
Detail
</td>
</tr>
<?php
}
?>
Please change your code
<th scope="row"><?php echo $stt++?></th>
to
<td scope="row"><?php echo $stt++?></td>
change th to td will fix your problem.
I got the following php foreach loop in the A page of my web appliation. And i want to use the $watson variable which is inside this loop in an other php B page. What i did is used this variable as a value in an extra input button:<input type="button"/ value="<?php echo $watson; ?>,so to be able to capture this var in javascript like you see below.
<tbody>
<?php
foreach($records as $r) {
$watson = $r->case_reference;
?>
<tr>
<td><?php echo escape($r->user); ?></td>
<td><?php echo escape($r->customer); ?></td>
<td><?php echo escape($r->vessel); ?></td>
<td><?php echo escape($r->country); ?></td>
<td><?php echo escape($r->port); ?></td>
<td><?php echo escape($r->eta); ?></td>
<td><?php echo escape($r->service_station); ?></td>
<td><?php echo escape($r->type_of_service); ?></td>
<td><?php echo escape($r->case_reference); ?></td>
<td><?php echo escape($r->status); ?></td>
<td><input type="button" value="<?php echo $watson; ?>" onclick="popEdit(this.value);" /></td>
</tr>
<?php
}
?>
</tbody>
The code for the onclick="popEdit(this.value);"function which pops up the B page mentioned above is :
function popEdit(str) {
window.open("example.php?watson="+str, "pop_edit_jobs",
"width=400,height=350,scrollbars=no,left=460,top=400")
}
And the php B page code starts as $ref_num = $_GET['watson']; so i can use the variable.
My problem is that i dont want the input/button in the A page to show the variable on it instead i want it to just show the word EDIT.But to do that i ll have to change its value and then i wont be able to capture this $watson var in javascript.
Any suggestions regarding how to achieve the above effect?
<td><input type="button" value="EDIT" onclick="popEdit('<?php echo $watson; ?>');" /></td>
should achieve the desired effect.
Wrap a form around your entire table, then use submit buttons:
<input type="submit" name="watson" value="<?php echo htmlspecialchars($watson); ?>" />
I need some help.
I used echo to display the ID but after I click each ID, the popup window appeared and will display the same page for all ID. I want to display a different page for each ID. How can I solve this? Thank you..
<td><a href="d1.php" onClick="javascript:void
window.open('d1.php','1382580890418','width=800,height=600,toolbar=1,menubar=1,location=1,s
tatus=1,scrollbars=1,resizable=1,left=0,top=0');return false;"><?php echo $row["ID"];
?></a></td>
<td><?php echo $row["NO"]; ?></td>
<td><?php echo $row["CATEGORY"]; ?></td>
<td><?php echo $row["TYPE"]; ?></td>
<td><?php echo $row["BRAND"]; ?></td>
<td><?php echo $row["MODEL"]; ?></td>
<td><?php echo $row["SERIAL"]; ?></td>
<td><?php echo $row["YEAR"]; ?></td>
<td><?php echo $row["DUEDATE"]; ?></td>
<td><?php echo $row["REGION"]; ?></td>
<td><?php echo $row["STATUS"]; ?></td>
Try with passing different name every row like :
<td>
<?php echo $row["ID"]; ?>
</td>
Different window name for every row by passing the row id as window names.
Ideally all rows should be handled by single window, by setting your logic at d1.php, but I still this can be a solution.