Display selected row on another page, on button click - php

I have a table reading out a few columns of a db, with an edit button in each row. All I am trying to do is, when the edit button is clicked, that row is displayed with all of its columns in another page. Any help would be great. I know it's simple, but I can get it to work. I am able to navigate to the next page, but not sure how to carry the id of the specific row and read that out. Thanks.
index. php
<form id="mainform" action="editFunding2.php">
<div class='row'>
<div class='col-12'>
<div class='table table-responsive'>
<table class='table table-striped table-bordered datatable active' id='grantTable'>
<thead>
<tr>
<th>FP ID</th>
<th>Short Title</th>
<th>PI</th>
<th>Department</th>
<th>Funding Type</th>
<th>Change Funding Type</th>
</tr>
</thead>
<tbody>
<?php
//Foreach loop iterates through each column of $getallrows function
foreach($allRows as $rowID => $rowInfo){ ?>
<tr>
<td><?php echo $rowInfo['fpID'];?></td>
<td><?php echo $rowInfo['shortTitle'];?></td>
<td><?php echo $rowInfo['PI'];?></td>
<td><?php echo $rowInfo['Department'];?></td>
<td><?php echo $rowInfo['fundingType'];?></td>
<!--Create dynamic id -->
<?php $rdDrop = "ddgrantType_".$rowInfo['fpID'];?>
<td>
<button type="submit" class="btn btn-danger" name="action" value='Change Funding Type'>Change Funding</button>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</form>
My editFunding2.php page
<div class='row'>
<div class='col-12'>
<div class='table table-responsive'>
<table class='table table-striped table-bordered datatable active' id='grantTable'>
<thead>
<tr>
<th>FP ID</th>
<th>Short Title</th>
<th>PI</th>
<th>Department</th>
<th>Division</th>
<th>Sponsor Name</th>
<th>Project Start</th>
<th>Project End</th>
<th>Funding Type</th>
<th>Yes/No</th>
<th>Proper Type If No</th>
<!-- <th>Exclusions</th>
<th>FP Durtation</th> -->
<th>Comment</th>
</tr>
</thead>
<tbody>
<?php
session_start();
$editRow = $_REQUEST['fpID'];
$mssql = mysqli_query("SELECT * FROM spacing.METADATA_WEBFORM WHERE FUNDING_PROPOSAL_ID = $fpID' ") or die (mysqli_error());
while($rowInfo = mysqli_fetch_array($mssql)) {
?>
<tr>
<td><?php echo $rowInfo['fpID'];?></td>
<td><?php echo $rowInfo['shortTitle'];?></td>
<td><?php echo $rowInfo['PI'];?></td>
<td><?php echo $rowInfo['Department'];?></td>
<td><?php echo $rowInfo['Division'];?></td>
<td><?php echo $rowInfo['sponsorName'];?></td>
<td><?php echo $rowInfo['Date_Project_Start']->format('Y-m-d');?></td>
<td><?php echo $rowInfo['Date_Project_End']->format('Y-m-d');?></td>
<td><?php echo $rowInfo['fundingType'];?></td>
<?php } ?>
<!--Create dynamic id -->
<?php $rdDrop = "ddgrantType_".$rowInfo['fpID'];?>
<td>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class='form-check-input' name="rdGrant[<?php echo $rowInfo['fpID'];?>]" value="Yes" id="rdYes" onclick="disable('<?php echo $rdDrop;?>')" checked/> Yes
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input class='form-check-input' type="radio" name="rdGrant[<?php echo $rowInfo['fpID'];?>]" value="No" id="rdNo" onclick="enable('<?php echo $rdDrop;?>')"/> No
</label>
</div>
</td>
<td>
<div class="dropdown">
<select class='form-control' name="ddgrantGroup[<?php echo $rowInfo['fpID'];?>]" id="<?php echo $rdDrop;?>" disabled>
<option value=''>Select Proper Funding Type</option>
<option value="Corporate Sponsor">Corporate Sponsor</option>
<option value="Federal">Federal</option>
<option value="Foundation Selected">Foundation Selected</option>
<option value="Internally Funded">Internally Funded</option>
<option value="State/Local">State/Local</option>
</select>
</div>
</td>
<td>
<div class="comment">
<textarea class="form-control" aria-label="With textarea" name="grantComment[<?php echo $rowInfo['fpID'];?>]" id="grantComment" placeholder="Comments"></textarea>
</div>
</td>
</tr>
</tbody>
</div>
</div>
</div>
<div class='row'>
<div class='col-12 text-right'>
<button type="submit" class="btn btn-secondary formsubmitbttn" name="action" value='save'>Save</button>
<button type="submit" class="btn btn-primary formsubmitbttn" name="action" value='complete'>Complete and Save</button>
</div>
</div>
</div>

Change your button to a
My Link to xx
In editFunding2.php :
$editRow = $_GET['id'];

Related

when i do form the popup window displays in just a second then hide again

I have popup it works normal i need to use method post to get my value from the input balise but the problem is when i do form the popup window displays in just a second then hide again and I need to click two time becausethe first time i got just the last result
<div class="List_modify">
<table class="list">
<thead class="topBar">
<tr>
<th>Prenom</th>
<th>Nom</th>
<th>CIN</th>
<th>Emails</th>
<th>Références</th>
<th>Photos</th>
<th>Niveau</th>
<th class="button_editer" style="vertical-align:middle"><span>Editer</span></th>
</tr>
</thead>
<?php $requet = "select * from Etudiants";
$resultat = mysqli_query($connecte, $requet);
while ($r = mysqli_fetch_array($resultat)) {
?>
<tbody class="container">
<tr>
<td>
<?php echo $r['Prenom']; ?>
</td>
<td>
<?php echo $r['Nom']; ?>
</td>
<td>
<?php echo $r['CIN']; ?>
</td>
<td>
<?php echo $r['Emails']; ?>
</td>
<td>
<?php echo $r['Matricule']; ?>
</td>
<td> <img src="image/<?php echo $r['Photo']; ?> " style="width: 150px; height:150px;"></td>
<td>
<?php echo $r['Niveau']; ?> </td>
<td>
<form method="POST" action="">
<input type="hidden" name="id" value="<?php echo $r['Id_Etudiant']; ?>">
<button class=" button" onclick="show()" style="vertical-align:middle" type="submit" name="submit"><span>Editer<i class=" fas fa-user-edit"></i></span>
</button>
</form>
</td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
<div class="background_page_modify" id="page_modify" onclick="hide()">
<div class="page_etudiant" onclick="event.stopPropagation()">
<div class="closebtn" id="closebtn" onclick="hide()">
<div class="circle"> +</div>
</div>
<div class="etudiant_box">
<?php
if (isset($_REQUEST['submit'])) {
$checkid = $_REQUEST['id'];
echo $checkid;
}
?>
</div>
</div>
</div>

Get php checkbox data from multiple tables

First I will tell what I want to achieve, and then I will explain how I was trying to do it.
I have two tables, one stores type of vessels with a description and their own Id. Then I have another table in wich the vessel type has been stored as text. My goal is to select each one (both records in both tables) with a checkbox in both and store in the table 2 the Id from the table 1.
I will introduce data, to help.
Table 1
1|Balandra|Some description
2|Bergantin|Some description
3|Whatever |Whatever.....
Table2
Balandra
Bergantin
Whatever
Then, I have created a php page that shows both tables with the checkbox I mentioned above. Checkboxes store the Table1 Id and Table2 vesseltypename.
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th class="hidden-xs">idtiponavio</th>
<th>Tipo de Navío</th>
<th>Descripción</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosdyncoop as $key => $navio) { ?>
<tr>
<td align="center">
<a href=<?php echo '../vista/modificar.php?id=' .
$navio['idtiponavio']; ?> class="btn btn-default"><em class="fa fa-
pencil"></em></a>
<a href=<?php echo '../datos/borrar.php?id=' .
$navio['idtiponavio']; ?> class="btn btn-default"><em class="fa fa-
trash"></em></a>
</td>
<td class="hidden-xs"><?php echo
$navio['idtiponavio']; ?></td>
<td><?php echo $navio['tiponavio']; ?></td>
<td><?php echo $navio['descripcion']; ?></td>
<td><input type="checkbox" name="agruparid" value=<?
php echo $navio['idtiponavio']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="col-md-6">
<div class="panel-body paneltodo">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th>Tipo de Navío</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosforsea as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-arrow-circle-o-left"></em>
</td>
<td><?php echo $navio['typevessel']; ?></td>
<td><input type="checkbox" name="agruparvessel" value=<?php echo $navio['typevessel']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
So, I want to check both table records and store the table1 Id in the table2 idtypevessel field.
I thought that a php file could store both items and call the update function with those parameters, like this:
<?php
require './modelo.php';
$idnavio = $_GET['agruparid'];
$vessel = $_GET['agruparvessel'];
Any suggestions, because I think I have to do a button to submit this parameters, but it must be working on both tables, and I don't know how to access both foreach loop at the same time.
Thanks in advance.
E. Salas
review bellow reference code to submit multi selected checkbox values
for multi selected checkbox submission you must use [] operator after name attribute in html
index.php
<form action="/checkbox.php" method="post">
<strong>Cars:</strong><br>
<?php
$cars = array("Volvo", "BMW", "Toyota");
$colors = array("Red", "Green", "Black");
foreach($cars as $single){
?>
<input type="checkbox" name="cars[]" value="<?php echo $single; ?>">
<?php
}
<br>
<strong>colors:</strong><br>
foreach($colors as $single){
?>
<input type="checkbox" name="colors[]" value="<?php echo $single; ?>">
<?php
}
?>
<br>
<input type="submit" value="Submit!">
</form>
checkbox.php
<?php
echo "<pre>";
var_dump($_POST);
exit;
In your case:
<form action="/checkbox.php" method="post">
<div class="col-md-6">
<div class="panel-body">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th class="hidden-xs">idtiponavio</th>
<th>Tipo de Navío</th>
<th>Descripción</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosdyncoop as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-pencil"></em>
<em class="fa fa-trash"></em>
</td>
<td class="hidden-xs"><?php echo $navio['idtiponavio']; ?></td>
<td><?php echo $navio['tiponavio']; ?></td>
<td><?php echo $navio['descripcion']; ?></td>
<td><input type="checkbox" name="agruparid[]" value=<?php echo $navio['idtiponavio']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="col-md-6">
<div class="panel-body">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th>Tipo de Navío</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosforsea as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-arrow-circle-o-left"></em>
</td>
<td><?php echo $navio['typevessel']; ?></td>
<td><input type="checkbox" name="agruparvessel[]" value=<?php echo $navio['typevessel']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<input type="submit" value="Submit!">
</form>
Finally I solved this with Javascript. One of my partners helped me, I post this to help people in my situation.
I created a script, here is the code:
<script type="text/javascript">
function cogeNavioDyncoopnet(){
var checkedValueNavioD = null;
var inputElements = document.getElementsByClassName('checknaviod');
for(var i=0; inputElements[i]; ++i){
if(inputElements[i].checked){
checkedValueNavioD = inputElements[i].value;
break;
}
}//return checkedValueNavioD;
var input_nav_dyn = document.getElementById("nav_dyn");
input_nav_dyn.value = checkedValueNavioD;
}
function cogeNavioForSea(){
var checkedValueNavioFs = null;
var inputElements = document.getElementsByClassName('checknaviofs');
for(var i=0; inputElements[i]; ++i){
if(inputElements[i].checked){
checkedValueNavioFs = inputElements[i].value;
break;
}
}//return checkedValueNavioFs;
var input_nav_fs = document.getElementById("nav_fs");
input_nav_fs.value = checkedValueNavioFs;
}
</script>
Then I created a Form below, that collects values and sends them to my .php control file.
<div class="hidden-xs">
<form class="hidden-xs" method="POST"
action="../datos/actualizarnavios.php">
<input id="nav_dyn" type="text" name="idnaviodyncoop">
<input id="nav_fs" type="text" name="navioforsea" >
<input id="botonasignar" type="submit" name="enviardatosdynfs">
</form>
</div>
I hope this helps. Thanks for the feedback, as always.

How to show multiple results in a query result?

I have a table that I have to populate him with a query result. One of the rows is the name of the group. My result3 inside the while is a query where I get the name of the group. I want to put that name in each row. But for some reason I can only get the first position of the query result. Can you help me?
This is my result3 variable query(in a resumed way):
$sql3 = "SELECT * from titulogrupo where idutilizador ={$_SESSION['id_utilizador']}";
$result3 = mysqli_query(mysqli_connect(", "u518178166_serra"), $sql3);...etc etc...
<table table id= "myTable" class="table table-hover"> <br>
<thead>
<tr>
<th>Os meus Chips</th>
<th>NIF</th>
<th>Marca de Exploracao</th>
<th>Marca do Auricular</th>
<th>Data de Nascimento</th>
<th>Observacoes</th>
<th>Estado</th>
<th>Data1</th>
<th>Data2</th>
<th>Data3</th>
</tr>
</thead>
<?php
while ($row = mysqli_fetch_array($result)){
?>
<tr>
<td><?php echo $row['numerochip'];?><input style="float: left; margin: 0 5px;" type="checkbox" value="<?php echo $row['numerochip']; ?>" name="numero[]" id="numero"></td>
<td><?php echo $row['NIF']; ?></td>
<td><?php echo $row['MarcaExploracao']; ?> </td>
<td><?php echo $row['MarcaAuricular']; ?> </td>
<td><?php echo $row['Data_Nascimento']; ?> </td>
<td><?php echo $row['observacoes'];?>
<div class="w3-container" id="....kli..">
<input style="display: none; type="text" id="numerochipescondido" name="numerochipescondido" value="<?php echo $row['numerochip']; ?>">
<input style="display: none; type="text" id="observacoesescondido" name="observacoesescondido" value="<?php echo $row['observacoes']; ?>">
<input style="display: none; type="text" id="idutilizadorescondido" name="idutilizadorescondido" value="<?php echo $_SESSION['id_utilizador']; ?>">
<center>
<button type="button" id="<?php echo $row['numerochip']; ?>" onclick="document.getElementById('id111').style.display='block'" class="glyphicon glyphicon-pencil changeobervations" width:50px height:50px;"></button>
</center>
</div>
</td>
<td>
<?php
if($row['velha']){
echo 'Velha ';
}
if($row['prenha']){
echo 'Prenha ';
}
if($row['refugo']){
echo 'Refugo ';
}
if($row['grupo4']){
while ($row = mysqli_fetch_array($result3)){
echo $row['titulogrupo'];
}
}
?>
</td>
<td><?php echo $row['Data1']; ?> </td>
<td><?php echo $row['Data2']; ?> </td>
<td><?php echo $row['Data3']; ?> </td>
</tr>
<?php } ?>
</table>
<br>
<input type="submit" class="btn btn-warning"name="submit_x" value="Submeter Lista de Animais a Encontrar(Individual)"> <br> <br>
<input type="submit" class="btn btn-danger"name="submit_y" value="Eliminar Animais Selecionados(Individual)"> <br> <br>
<form action="deletedb.php" method="post">
<input type="submit" class="btn btn-danger"name="submit_d" value="Apagar a minha lista total">
</form>
</form>
<br>
</br>
<table class="table table-hover" style="width:300px">
<thead>
<tr>
<th>Os meus Chips a encontrar</th>
</tr>
</thead>
<?php
while ($row = mysqli_fetch_array($result2)){
?>
<tr>
<td><?php echo $row['ovelhas'];?></td>
</tr>
<?php } ?>
<!-- Começa aqui o apagar -->
<form action="apagarOvelhasEncontrar2.php" method="post">
<br>
<tr>
<td>
<button type="submit" name="submit_x" class="btn btn-danger">Apagar Ovelhas a Encontrar</button>
</td>
</tr>
</form>
</table>
</br>
</div>
Use a different variable when fetching $result3 etc.
if($row['grupo4']){
while ($row3 = mysqli_fetch_array($result3)){
echo $row3['titulogrupo'];
}

Jquery mouse over event

I want to show a hidden div when I mouse over a link on my table cell. The event only fires up on the first row. This is what i did:
$(document).ready(function(){
$("#show_div").mouseover(function() {
$("#hello").css('visibility', 'visible');
});
$("#hello").mouseover(function() {
$("#hello").css('visibility', 'visible');
});
$("#hello").mouseout(function() {
$("#hello").css('visibility', 'hidden');
});
});
<form action="" method="post">
<table class="table table-bordered table-hover">
<div id="bulkOptionContainer" class="col-xs-4">
<select class="form-control" name="bulk_options" id="">
<option value="">Select Option</option>
<option value="publish">Publish</option>
<option value="draft">Draft</option>
<option value="delete">Delete</option>
</select>
</div>
<div class="col-xs-4">
<input class="btn btn-success" type="submit" name="submit" value="Apply"/>
<a class="btn btn-primary" href="posts.php?source=add_post">Add New</a>
</div>
<thead>
<tr>
<th><input type="checkbox" name="checkbox[]" id="selectAllCheckBoxes"></th>
<th>Id</th>
<th>Author</th>
<th scope="col">Title</th>
<th>Category</th>
<th>Status</th>
<th>Image</th>
<th>Tags</th>
<th>Comments</th>
<th>Date</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php $query = "SELECT * FROM post ORDER BY post_id DESC";
$result_set = mysqli_query($link, $query);
confirm_query($result_set);
while ($row = mysqli_fetch_assoc($result_set)):?>
<tr>
<td><label><input type="checkbox" class="checkBoxes" name="checkBoxArray[]"
value="<?php echo $row['post_id']; ?>"></label></td>
<td><?php echo $row['post_id'] ?></td>
<td><?php echo $row['post_author'] ?></td>
<td width="100%">
<!-- link to over-->
<a id="show_div"
href="../post.php?p_id=<?php echo $row['post_id'] ?>"><?php echo $row['post_title'] ?></a>
<!-- div to become visible on hover-->
<div id="hello" style="visibility:hidden;">
<p>post</p>
</div>
</td>
<td><?php echo sel_cat_byId($row['post_category_id']) ?></td>
<td><?php echo $row['post_status'] ?></td>
<td><img width="100" class="img-responsive" src="../images/<?php echo $row['post_image'] ?>"></td>
<td><?php echo $row['post_tag'] ?></td>
<td><?php echo $row['post_comment_count']; ?></td>
<td><?php echo $row['post_date'] ?></td>
<td><a class="btn btn-danger" href="posts.php?delete=<?php echo $row['post_id']; ?> "
onclick="alert('Are You Sure?')">Delete</a></td>
</td>
<td><a class="btn btn-success" href="posts.php?source=edit_post&edit=<?php echo $row['post_id']; ?>">Edit</a>
</td>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</form>
****the event only fires up on the first row.
Thanks
First replace your id with class and then try this
$(".show_div").mouseover(function() {
$(this).next(".hello").css('visibility', 'visible');
});
$(".show_div").mouseout(function() {
$(this).next(".hello").css('visibility', 'hidden');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<a class="show_div"
href="#">abc</a>
<!-- div to become visible on hover-->
<div class="hello" style="visibility:hidden;">
<p>post</p>
</div>

How to make a drop down that include years and when a year is selected, it gets the people who registered in that year in a table using php

<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th></th>
<th>Business Name</th>
<th>Commencement Date</th>
<th>Registered?</th>
<th>Business Address</th>
<th>Contact Details</th>
<th>Contact Name</th>
<th> </th>
</tr>
</thead>
<tbody>
<?
db_connect();
$result=mysql_query("select * from hbs_participants_register ORDER BY hbs_id DESC");
$num_result=mysql_num_rows($result);
?>
<tr>
<?
for ($i=0; $i<$num_result; $i++) {
$row=mysql_fetch_array($result);
?>
<td width="10"><div align="left">
<?php echo $i+1; ?>
</div>
</td>
<td><div align="left">
<? echo $row['hbs_bus_name'] ?>
</div>
</td>
<td><div align="left">
<? echo $row['hbs_com_date'] ?>
</div>
</td>
<td><div align="left">
<? echo $row['hbs_bus_reg']; ?>
<br /> <strong><?php if (!empty($row['hbs_bus_regnumber'])) {
echo "Reg No. ".$row['hbs_bus_regnumber'];
} else {} ?></strong>
</div>
</td>
<td><div align="left">
<? echo $row['hbs_bus_address']; ?>
<br />
</div>
</td>
<td><div align="left">
<? echo $row['hbs_email']; ?>
<br />
<? echo $row['hbs_phone']; ?>
<br />
<? echo $row['hbs_url']; ?>
<br />
</div>
</td>
<td><div align="left">
<? echo $row['hbs_contact_name']; ?>
</div>
</td>
<td>
<div class="btn-group">
<button class="btn btn-small dropdown-toggle"
data-toggle="dropdown">
<i class="icon-cog"></i> <strong
style="font-size: 14px; padding: 5px 0px"> Manage</strong><span
class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a
href="../../print-busreg.php?hbs_id=<?php echo $row['hbs_id'];?>"
target="_blank"><i class="icon-list"></i> Full Details</a>
</li>
<li><a
href="?w=plugins/HBS%202015/delete-busreg&hbs_id=<?php echo $row['hbs_id'];?>&action=delete"
onclick="return confirm('Are you sure you want to delete?')"><i
class="icon-trash"></i> Delete</a>
</li>
</ul>
</div>
</td>
</tr>
<? } ?>
</tbody>
</table>
I believe this should work, assuming you are storing the data together with the year it was submitted. This is not the whole code you need, just the part which lets you select a year and get it from the Dbase.
<form method="get" action="page.php" enctype="multipart/form-data">
year:
<select name="selectedYear">
<option value="2000">2000</option>
<option value="2001">2001</option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
</select>
<input type="submit" name="submit">
</form>
PHP
<?php
$year = $_GET['selectedYear'];
?>
So then you just get all the columns that contain that year:
mysql_query('"select * from hbs_participants_register WHERE year LIKE" . $year . "ORDER BY hbs_id DESC"');

Categories