I have brought in data from the database using mysqli_fetch_array();
I put the data from the database and insert it into a table
so the tbody looks like this:
<tbody>
<?php
$query = mysqli_query($db, "SELECT * FROM project");
$index = 1;
while($data = mysqli_fetch_array($query)) {?>
<tr>
<td><?php echo $index; ?></td>
<td><?php echo $data['project_name']; ?></td>
<td><?php echo $data['client_name']; ?></td>
<td><a href="#"</a>View</td>
<td style="text-align:center">
<a data-id="$data['id']" href="dashboard.php?remove_project=<?php echo $data['id']; ?
>"><i style="color: red" class="fa fa-times"></i></a>
</td>
</tr>
<?php $index++; }; ?>
</tbody>
I want a situation where when I click view, a modal pops up showing me data exactly from that Id, the goal is to click on the view and see a modal or a registered user. So I want to click on View and then the modal shows me data from that click, and when I click another View on the table, it shows me different data.
Related
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.
I have question about how i shall do this.
First i have taken out a list from a mysql database which.
What I want to do is to be able to click on one of these items in the list so that I can get the underlying facts for this particular item.
Now i want to use this as a link to get one row from the database.
The database is done and the list i can see in a website but i dont get the last part to work
show_all_symbol.php
//This show the list
<?php
include 'connect.php';
$sql = "SELECT * FROM t1_symbolism ";
$q = $pdoconn->query($sql);
$q ->setfetchmode(PDO::FETCH_ASSOC);
?>
<table>
<head>
<tr><th>Symbol</th><th>Alternativtnamn</th> <th>Symboltyp</th></tr>
</thead>
<tbody>
<?php while ($row = $q->fetch()): ?>
<td><img src="<?php echo "/symbol/",$linksbild,($row['symb_type']),"/",($row['symb_pic']); ?>"/></td>
<tr>
<td> <a id="leftside_meny" href= <?php echo "/symbol/show_symbol.php";?> target= "texten"> <?php echo ($row['symb_name']); ?></a></td>
<td><?php echo ($row['symb_name_other']); ?></td>
<td><?php echo ($row['symb_type']); ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</body>
show_symbol.php
<body>
<?php
$funamn = trim($_POST['symbname']);
include 'connect.php';
$sqlanswer = $pdoconn->query(" SELECT * from t1_symbolism where symb_name '$funamn'");
$row = $sqlanswer->fetch();
?>
<table >
<thead>
<tr><th>Symbol</th><th>Symbolnamn</th><th>Alternativtnamn</th> <th>Symboltyp</th><th>Fakta</th></tr>
</thead>
<tr>
<td><img src="<?php echo "/symbol/",$linksbild,($row['symb_type']),"/",($row['symb_pic']); ?>" width="250" height="250"/></td>
<td><?php echo ($row['symb_name']); ?></td>
<td><?php echo ($row['symb_name_other']); ?></td>
<td><?php echo ($row['symb_type']); ?></td>
<td><?php echo ($row['symb_history']); ?></td>
</tr>
</table>
</body>
What i want to do is to use this part as Use this part as a clickable link so I can view a record in the table.
<td> <a id="leftside_meny" href= <?php echo "/symbol/show_symbol.php";?> target= "texten"> <?php echo ($row['symb_name']); ?></a></td>
Thank in the advance!
it looks like you are looking for a way to pass this value $row['symb_name'] to this value $_POST['symbname']. Here's what i think you should try :
in your show_all_symbol.php
<td>
<a id="leftside_meny" href="<?php echo "/symbol/show_symbol.php?symb_name=" . $row['symb_name'];?>" target="texten">
<?php echo ($row['symb_name']); ?>
</a>
</td>
in your show_symbol.php
$funamn = trim($_GET['symb_name']);
If you want to use $_POST then you will have to either figure a way to make a form out of each clickable element and configure it to make a POST or do it using javascript or jquery.
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.
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.
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';