1. If the only thing you are going to send is inside the row, then make a form for each row (and hide it with styles).
<?php
$res_listado = array(
array(
'id_unico'=>1,
'nombre'=>'Juan Perex',
'datovergonzoso'=>'le huelen los pies',
),
array(
'id_unico'=>2,
'nombre'=>'Arnaldo Biroya',
'datovergonzoso'=>'ronca en Do mayor',
),
array(
'id_unico'=>3,
'nombre'=>'Emilio Fuentes',
'datovergonzoso'=>'No sabe comer chicles',
),
array(
'id_unico'=>4,
'nombre'=>'Rodolfo Innuit',
'datovergonzoso'=>'le da verguenza decirlo',
),
);
?>
<!DOCTYPE html>
<html lang="es">
<head>
<title>datatablesvaloroculto</title>
<style>
.markrow{background:#fe0;}
</style>
</head>
<body>
<table name="tableRoster" id="id_tableRoster">
<thead id="encabezados">...</thead>
<tbody>
<?php foreach ($res_listado as $key => $value) { ?>
<tr onclick="enviar2(<?php echo $value['id_unico']; ?>)">
<td align="center">
<form name="formListado-fila-<?php echo $value['id_unico'];?>" action="detalleDir.php" method="POST" style="display:none;">
<input name="idMedico" type="hidden" value="<?php echo $value['id_unico']; ?>" />
</form>
<?php echo $value['nombre'];?>
</td>
<td>
<?php echo $value['datovergonzoso'];?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</body>
<script>
function enviar2(id) {
elForm= document.getElementsByName('formListado-fila-'+id)[0];
elForm.submit();
}
</script>
</html>
the detailDir.php receives what you send in the form corresponding to the row clicked (in this case there is only one input called "idMedico"):
<?php
var_dump($_POST);
?>
will result in:
array(1) {
["idMedico"]=>
string(1) "2"
}
if you click on row 2
If you need to send more own data of each row (row) you include them as inputs within the form.
2. If instead the extra data is common to all the rows and would be repeated a lot, then what you can do is create the form outside the table, add a hidden field for the id and set it before submit:
<?php
$res_listado = array(
array(
'id_unico'=>1,
'nombre'=>'Juan Perex',
'datovergonzoso'=>'le huelen los pies',
),
array(
'id_unico'=>2,
'nombre'=>'Arnaldo Biroya',
'datovergonzoso'=>'ronca en Do mayor',
),
array(
'id_unico'=>3,
'nombre'=>'Emilio Fuentes',
'datovergonzoso'=>'No sabe comer chicles',
),
array(
'id_unico'=>4,
'nombre'=>'Rodolfo Innuit',
'datovergonzoso'=>'le da verguenza decirlo',
),
);
?>
<!DOCTYPE html>
<html lang="es">
<head>
<title>datatablesvaloroculto</title>
<style>
.markrow{background:#fe0;}
</style>
</head>
<body>
<form name="formListado" action="detalleDir.php" method="POST">
<input name="idMedico" type="hidden" value="desconocido" />
<input name="unCampoGenerico" type="hidden" value="informacion oculta no tan oculta" />
<input name="otroCampoGenerico" type="hidden" value="otra informacion oculta no tan oculta" />
deja un comentario antes de clickar:
<input name="comentario" type="text" />
<table name="tableRoster" id="id_tableRoster">
<thead id="encabezados">...</thead>
<tbody>
<?php foreach ($res_listado as $key => $value) { ?>
<tr onclick="enviar2(<?php echo $value['id_unico']; ?>)">
<td align="center">
<?php echo $value['nombre'];?>
</td>
<td>
<?php echo $value['datovergonzoso'];?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</form>
</body>
<script>
function enviar2(id) {
elInput= document.getElementsByName('idMedico')[0];
elInput.value=id;
elForm= document.getElementsByName('formListado')[0];
elForm.submit();
}
</script>
</html>
example of the received with the second code:
array(4) {
["idMedico"]=>
string(1) "3"
["unCampoGenerico"]=>
string(32) "informacion oculta no tan oculta"
["otroCampoGenerico"]=>
string(37) "otra informacion oculta no tan oculta"
["comentario"]=>
string(18) "voy a clickar el 3"
}