Click table row to load new table - php

So I have a table loaded on the my page, Is it possible to click on a row and have it load another table with the same ID from my database? For instance a table with customer orders is already loaded, when i click on one of the rows is it possible to have a second table load with the order record with the same id?
This is my code loading the first table. I was thinking maybe i could use a check box value? Or maybe some sort of jquery all though I dont know much about jquerys
I was able to find this code that prints the selected row to a message box but Im not sure how or even if it can do what ive described?
this is essentially what i want to do http://www.youtube.com/watch?v=cobidLA_KVU&feature=youtu.be
<table border="5",th,td, cellspacing="5", cellpadding="5", width="500", align="center">
<tr>
<th>TP ID</th>
<th>Permit Deny</th>
<th>Level</th>
<th>Session</th>
<th>Information Specialist</th>
</tr>
<?php foreach ($results as $row): ?>
<tr>
<td><?php echo $row->TP_ID ?></td>
<td><?php echo $row->Permit_or_Deny ?></td>
<td><?php echo $row->Level ?></td>
<td><?php echo $row->Session ?></td>
<td><?php echo $row->Information_specialist ?></td>
</tr>
<?php endforeach ?>
</table>
var i = 1;
$('td').each(function(){
$(this).addClass('col'+i);
i = i+1;
});
$('table').find("td:not(.col4)").on('click',function(){
alert($(this).text());
})

You can also use jQuery/Ajax. Make a $_GET from it and request the server for a new GET variable.

Related

How to hide table rows that fetch the info from a database based on string given and when a button is pressed

An HTML table is given in which there are people (agents in this case) who have the following information displayed Id, Name, Rank, Location, and Status. Status can have 3 values. Online, Offline, Disconnected. Based on the status that one of the agents has I want to put 3 buttons as such Online, Offline, and Disconnected, and when a button is pressed to hide the other rows with different values. For example, if I press Online, table rows on the HTML side that contain the status Offline and Disconnected disappear, this goes for the others too the other way around. I have no idea to achieve what I said earlier and I am open to any solution that is deemed to resolve my problem.
<table id="main_table">
<tr>
<td>Id</td>
<td>Agent Name</td>
<td>Agent Rank</td>
<td>Agent Location</td>
<td>Status</td>
</tr>
<?php
require 'CMS/processing/conn.php';
$result = mysqli_query($con,"SELECT * FROM agents");
while($info = mysqli_fetch_array($result)) {
?>
<tr>
<td><?php echo $info['id']; ?></td>
<td><?php echo $info['agentName']; ?></td>
<td><?php echo $info['agentRank']; ?></td>
<td><?php echo $info['locationNames']; ?></td>
<td><?php echo $info['agentStatus']; ?></td>
</tr>
<?php
}
?>
</table>
Try using the below logic : Create 3 buttons with <a> and pass status value as GET to the same page then while fetching check whether it has GET or not
Note:This is not a answer :passing direct GET value to sql query may cause some security issues
Online//put the status value based on your status
Offline//put the status value based on your status
Disconnected//put the status value based on your status
<table id="main_table">
<tr>
<td>Id</td>
<td>Agent Name</td>
<td>Agent Rank</td>
<td>Agent Location</td>
<td>Status</td>
</tr>
<?php
require 'CMS/processing/conn.php';
if(isset($_GET['status']))
{
$result = mysqli_query($con,"SELECT * FROM agents where agentStatus='".$_GET['status']."'");
}
else
{
$result = mysqli_query($con,"SELECT * FROM agents");
}
while($info = mysqli_fetch_array($result)) {
?>
<tr>
<td><?php echo $info['id']; ?></td>
<td><?php echo $info['agentName']; ?></td>
<td><?php echo $info['agentRank']; ?></td>
<td><?php echo $info['locationNames']; ?></td>
<td><?php echo $info['agentStatus']; ?></td>
</tr>
<?php
}
?>
</table>
I'd use javascript within a tag or jQuery since this sounds like you need dynamic functionality on a static webpage.
For your button pass in the name of the function you're creating inside your tag
<button onclick="yourFunctionName(yourString)"></button>
Inside your tag have the function accept the yourString paramater
function yourFunctionName(yourString){
if(yourString === "whatever"){
$('tbody tr').hide()
$('tbody tr').show()
}
etc! Let me know if you need any more clarification on anything
Output echo an attribute on each row <tr data-status="online"> etc.
Then in script use document.querySelectorAll("tr[data-status='online'] to find all rows with that status, loop thru the array and toggle each row style.display to 'table-row' or 'none' as required.
You could also do the same using CSS by assigning a class <tr class="online"> etc. Then in script dynamically altering the CSS definition of that class, changing the display to 'table-row' or 'none' as required.

create a clickable link in MySQL results

I'm in the process of learning some coding. I am looking to create the results of MySQL results clickable. I would like the name (first and last name) to be "clickable" so they can link to the customer record to view. Thanks in advance for your help!
<table class="list"; >
<tr>
<th>Name</th>
<th>Address</th>
<th>Email</th>
<th>Phone</th>
</tr>
<?php while($customers = mysqli_fetch_assoc($customer_set)) { ?>
<tr>
<td><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></td>
<td><?php echo h($customers['address1']. ' '.$customers['city'].', '.$customers['state'].' '.$customers['zip']); ?></td>
<td><?php echo h($customers['email1']); ?></td>
<td><?php echo h($customers['phone1']); ?></td>
</tr>
<?php } ?>
Thanks,
If you want clickable first name and last name then you need to add anchor tag with view url like below examples.
Example (send first name and last name separately)
<td><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></td>
Better solution is you can send id of user . For example i am asuming you have one column id in customers table then you can pass id like below example
<td><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></td>
Note: You can encrypt id by using some hash methods to securely pass id of user.
Now when you click on these links you will redirect on view page where you can get these id or firstname, lastname by using GET method.
Example
view-record.php
<?php
if(isset($_GET['uid'])) {
$userid = $_GET['uid']; //please add some validation before using this value.
}
?>
You need to use the <a> (anchor) html tag like this:
<table class="list"; >
<tr>
<th>Name</th>
<th>Address</th>
<th>Email</th>
<th>Phone</th>
</tr>
<?php while($customers = mysqli_fetch_assoc($customer_set)) { ?>
<tr>
<td><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></td>
<td><?php echo h($customers['address1']. ' '.$customers['city'].', '.$customers['state'].' '.$customers['zip']); ?></td>
<td><?php echo h($customers['email1']); ?></td>
<td><?php echo h($customers['phone1']); ?></td>
</tr>
<?php } ?>
Replace the url http://example.com/... with whatever real url you want to use for the link.

Update an entry in the database from a single row in a table using a submit button cakephp

I have a page that displays a table of people that have not been checked in yet and one of the columns in this table is a "process" button that when clicked should update their processed time in the database to the time of the click. How can I update each users processed time when their processed button is clicked without having to input any extra information? (if that is at all possible)
I have a controller called new_student_arrival_reservations that accesses a table in my database with the corresponding name (UsersNewStudentArrivalReservation). Here's the code for my table displaying the people that need to be processed.
<table class="table table-striped table-hover">
<thead>
<tr><th>Name</th><th>ID</th><th>Program #</th><th>Residence Hall</th><th>Room Number</th><th>Process</th></tr>
</thead>
<tbody>
<?php foreach($newStudents as $id => $newStudent): ?>
<tr>
<td><?= $newStudent['UsersNewStudentArrivalReservation']['student_name']; ?></td>
<td><?= $newStudent['UsersNewStudentArrivalReservation']['student_id']; ;?></td>
<td><?= $newStudent['UsersNewStudentArrivalReservation']['checkin_num']; ?></td>
<td><?= $newStudent['UsersNewStudentArrivalReservation']['res_hall']; ?></td>
<td><?= $newStudent['UsersNewStudentArrivalReservation']['room_number']; ?></td>
<td>
<button type="button">Process</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
The table displays perfectly and all of the information is correct. As previously stated, I would like the process button on each row to update that persons processed time.
Please let me know if any other information is needed. Thank You!

user ID and Dropdown sql php server side

the code for the view page:
<table id='display'>
<thead>
<tr>
<th>ID</th>
<th>NAME</th>
<th>DEPARTMENT</th>
<th>TELEFON</th>
<th>FAKS</th>
<th>E-MAIL</th>
<th>DATA</th>
<th>PURPOSE</th>
<th>ACTION</th>
</tr>
</thead>
<tbody>
<?php
$connect = mysql_connect("localhost","root","");
if (!$connect){
die(mysql_error());
}
mysql_select_db("permohonan_data");
$option = '';
$results = mysql_query("SELECT * FROM pemohon ORDER BY id DESC");
$option .='<select>';
while ($row = mysql_fetch_array($results)){
?>
<tr>
<td><?php echo $row['id']?></td>
<td><?php echo $row['name']?></td>
<td><?php echo $row['unit']?></td>
<td><?php echo $row['telefon']?></td>
<td><?php echo $row['faks']?></td>
<td><?php echo $row['email']?></td>
<td><?php echo $row['data']?></td>
<td><?php echo $row['purpose']?></td>
<td><?php echo $option .="<option value='" .$row['action']. "'>".$row['action']."</option>"?></td>
</tr>
<?php
}
$option .='</select>';
?>
</tbody>
</table>
the ouput:
the full detail contains id, name, position, department, institute, email, telefon and so on which doesnt show on the table because of lack of space. my question is, how when I clicked the ID number(auto increrment) of any user, I could see the full details of the user? like in a popup form?
and my dropdown for action column are empty, supposedly have 'approve' and 'disapprove' option but I didnt know how to insert that because its for admin to valid the thing, not the user. so I can't put the option on the client side where the user is. how can I create a new client side just for admin?
idk. please help. :(
change
<td><?php echo $row['id']?></td>
to
<td><?php echo "<a href='full_details.php?id=".$row['id']."'>".$row['id']."</a>" ?></td>
create a page called full_details.php and use the id to query the db
Using jQuery you can do that.
using a click event you can send id to a "full_details" page and show using a popup the data that page returns back.
See here: jquery.com
To use jquery you have include it on your page using tag and after that you can write your own function to receive click action on the id and after that you can send async request to your page and show the result without reload the page.

Hide column of sql results and and show below table onClick

I have a table that displays SQL results, however I would like the table to display certain results, and display more upon a click, below the table in a div tag. So far I have this code that displays,'title' and 'email' and the 3rd column which will trigger a JS function and display 'details' in a div tag... How do I use JavaScript to display the specific details and hide those details when a second row details is clicked and replace the first 1?
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['title']; ?></td>
<td><?php echo $rows['email']; ?></td>
<td>More details...</td>
</tr>
EDITED:
After a comment I received, here is my entire code of the table with the div element with the id "details"
<table>
<tr>
<td><strong>Investment Title</strong></td>
<td><strong>Email</strong></td>
<td><strong>Details</strong></td>
</tr>
<?php
// Start looping table row
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['title']; ?></td>
<td><?php echo $rows['email']; ?></td>
<td>More details...</td>
</tr>
<?php
// Exit looping and close connection
}
mysql_close();
?>
<tr>
</tr>
</table>
<div id="detail"></div>
Im not sure if this is what you want to do but you can try something like this. I hope this helps
HTML
<table>
<tr>
<td><strong>Investment Title</strong></td>
<td><strong>Email</strong></td>
<td><a href='#' id='show_details'>More Details</a></td>
</tr>
<tr>
<td><?php echo $rows['title']; ?></td>
<td><?php echo $rows['email']; ?></td>
<td id='details'><?php echo $rows['details'];?></td>
</tr>
</table>
Javascript - JQuery
$(document).ready(function()
{
$('#details').hide(); //on ready hide the td details
$('#show_details').click(function()
{
$('#details').show();
});
});
UPDATE
YOU MEAN LIKE THIS SEE MY FIDDLE
Without JQuery:
HTML
<td id='details'>The details are in here...</td>
<td id='details1'>The other details are in here...</td>
Javascript
document.getElementById('details').style.display = 'table-cell';
document.getElementById('details1').style.display = 'none';

Categories