modal is triggered when i go to another page - javascript

i have three buttons (view,update,delete) , the view button is an href that goes to another page and brings an id with it, while my update triggers a modal. my problem is that when i click the view button it goes to the other page but it also triggers the update modal.
home.php
<?php
foreach($schedRow as $row)
{
?>
<tr>
<td><?php echo $row['subject_db']; ?></td>
<td><?php echo $row['section_db']; ?></td>
<td><?php echo $row['sched_day']; ?></td>
<td><?php $stime=$row['start_time'];
$etime=$row['end_time']; echo "".date('h:i a',strtotime($stime))." ~ ".date('h:i a',strtotime($etime))."";?></td>
<td>
View
<a href="#" class="btn btn-warning" data-toggle="modal"
data-target="#updateModal-<?php echo $row['sched_id']; ?>">Update</a>
Delete
<?php include'modal_update_sched.php'; ?>
</td>
</tr>
<?php
}
?>
heres the id of my modal
id="updateModal-<?php echo $row['sched_id']; ?>"

i solved it, the problem is that i called the modal in my view.php thats why it keeps triggering, note that i separated the code for my modal in another php file named modal_update_sched.php , i somewhat had an include 'modal_update_sched.php'; in my view.php, deleting it solved my problem.

Related

Call 'onClick' Code every time the page loads

I have some php/html that creates a dynamic table with a set of links. When the link is clicked it loads a page $url1 and called a function called 'update' which makes a mysql call.
I am removing the table and modifying the mysql to return a single row. I want the code to 1)load the linked page ($url1) 2)run the update function that is called by onclick.
Original Table
<tr>
<td><?php echo $i; ?></td>
<td><a href="<?php echo $url1; ?>" target="_blank" class="url" onclick="update('<?php echo $row['node']; ?>');"/>Run</td>
<td><?php echo $row['level1_text']." - ".$row['level2_text']." - ".$row['level3_text']." - ".$row['level4_text'] ?></td>
<td><?php echo $row['last_run_date']; ?><input type="text" class="node" value="<?php echo $row['node']; ?>" hidden></td>
<td id="cnt"><?php echo $row['run_count']; //$idate=explode(" ",$row['insertdate']); $bdate=explode("-",$idate[0]); echo $bdate[2]."-".$bdate[1]."-".$bdate[0]; ?></td>
</tr>
I started with the 'update' function, i figured I could reduce the sql statement to return only 1 row and call the update function with this code.
<script type="text/javascript">update('<?php echo $row['node']; ?>');</script>
That doesn't seem to work so I further simplified the code for testing but my update function is not being called.
<script type="text/javascript">update('525');</script>
Any pointers? Is there a good way call this function on page load and then load the page at $url?

Datatables can not be responsive as example

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.

how to change user id to their name in php?

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>
...

Delete a row javascript using row id

Hi guys I have a table created by php in this way:
foreach ($query as $row): ?>
<tr id="<?php echo $row->aic;?>" >
<td><?php echo $row->aic; ?></td>
<td><?php echo $row->denominazione ?></td>
<td><?php echo $row->quantita; ?></td>
<td><?php echo $row->alert; ?></td>
<td>
<a id="bt_modifica"
class="btn btn-default btn-xs"
data-toggle="tooltip"
data-placement="top"
title=""
data-original-title="Modifica">
<img src="<?php echo base_url(); ?>template/images/Modifica.png">
</a>
<a id="bt_elimina>"
class="btn btn-default btn-xs"
data-toggle="tooltip"
data-placement="top"
title=""
data-original-title="Elimina"
onclick="deleteRow(<?php echo $row->aic ?>))">
<img src="<?php echo base_url(); ?>template/images/Elimina.png">
</a>
</td>
</tr>
<?php
endforeach; ?>
</tbody>
I need to delete row by rowId. This table has the dynamics id.
The columns ids are the same id of the sql table; in effect aic is id of sql table! In this way I are sure that the HTML row id is unique.
This is script
function deleteRow(rowID)
{ var row = document.getElementById(rowID);
row.parentElement.removeChild(row);
alert(rowID);
}
}
this code don't delete row.
Change this:
onclick="deleteRow(deleteRow(<?php echo $row->aic ?>))">
to
onclick="deleteRow(<?php echo $row->aic ?>)">
Another potential issue is that this:
<?php echo $row->aic ?>
may not be a number. So, you need to quote it. That is, change:
onclick="deleteRow(<?php echo $row->aic ?>)">
to:
onclick="deleteRow(\"<?php echo $row->aic ?>\")">
2 issues -
The one that might be causing issue - Incorrect Function Name
Other one - Calling deleteRow() twice - within each other (this should not cause any issue though)
So, just change -
function eliminaProdotto(rowID)
to -
function deleteRow(rowID)
Edit:
Based on modified question -
Is $row->aic a string? If yes, then add quotes around it...
onclick="deleteRow('<?php echo $row->aic ?>')"

Capturing a PHP var inside a foreach loop in javascript and using it in an other PHP page.

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); ?>" />

Categories