Salve a tutti, avrei bisogno di un'aiuto:
ho creato una pagina php con all'interno una tabella con i risultati di una query che sfrutta la funzione di righello seguendo le istruzioni di html.it (ovvero tutta la riga diventa cliccabile per il collegamento scritto nell'ultimo dato del record ).
E funziona perfettamente.
Esce la tabella, ben formattata con il suo css e con il righello funzionante, man mano che scorri sui risultati della tabella si evidenzia l'intera riga ed è interamente cliccabile.
Il problema sorge quando cerco di mettere una seconda tabella nella stessa pagina, nonostante abbia provato a dare id diverso, script java distinto per tabella. La prima non riesce più a sfruttare il righello, ma la seconda si. Come faccio? Se rimuovo una delle due tabelle dalla pagina la rimanente diventa funzionante.
Credo sia un problema di javascrip che non so come risolvere.
Vi posto il codice:
<div id="corpo" >
<script type="text/javascript">
$(document).ready(function()
{
$("#myTable").tablesorter();
}
);
</script>
<script type="text/javascript">
onload=function(){
Righello("myTable");
}
function Righello(IDtabella){
trs=document.getElementById(IDtabella).tBodies[0].rows;
for(i=0;i<trs.length;i++){
tds=trs[i].cells;
trs[i].link=tds[tds.length-1].getElementsByTagName("a")[0].href;
trs[i].title= "Visita " + trs[i].link;
trs[i].style.cursor="pointer";
trs[i].onclick=function(){document.location.href=this.li nk};
trs[i].onmouseover = function(){this.className="corrente";}
trs[i].onmouseout = function(){this.className="";}
}
}
</script>
<h3> PROSSIMI EVENTI </h3>
<?php
// inclusione del file di classe
include "funzioni_mysql.php";
// istanza della classe
$data = new MysqlClass();
// chiamata alla funzione di connessione
$data->connetti();
// query per l'estrazione dei record
$ev_sql = $data->query("SELECT * FROM ev WHERE evgiorno between CURDATE() AND '2099-01-01' ");
// controllo sul numero di record presenti in tabella
if(mysql_num_rows($ev_sql) > 0){
?>
<table cellpadding="0" cellspacing="1" border="0" id="myTable" class="tablesorter">
<thead>
<tr>
<th><h3>Data</h3></th>
<th><h3>Regione</h3></th>
<th><h3>Citta</h3></th>
<th><h3>Societá</h3></th>
<th class="nosort" width="57px"><h3>Evento</h3></th>
</tr>
</thead>
<tbody>
<?php
// estrazione dei record tramite ciclo
while($ev_obj = $data->estrai($ev_sql)){
$evid = $ev_obj->evid;
$evnome = stripslashes($ev_obj->evnome);
$evgiorno = date($ev_obj->evgiorno);
$evregione = stripslashes($ev_obj->evregione);
$evcitta = stripslashes($ev_obj->evcitta);
$evpalid = stripslashes($ev_obj->evpalid);
$leggi_tutto = "<a href=\"evento.php?evid=$evid\"> Dettagli </a>\n";
?>
<tr>
<td><?PHP echo "<h5>". $data->format_data($evgiorno) . "</h5>\n"; ?></td>
<td><?PHP echo "<h5>". $evregione . "</h5>\n"; ?></td>
<td><?PHP echo "<h5>". $evcitta . "</h5>\n"; ?></td>
<td><?PHP echo "<h5>". $evpalid . "</h5>\n"; ?></td>
<td> [img]image/find16.png[/img] <?PHP echo "<h5>". $leggi_tutto . "</h5>\n"; ?></td>
</tr>
<?PHP
}
?>
</tbody>
</table>
<?PHP
}else{
// notifica in assenza di record
echo "Nessun evento futuro presente ad oggi !";
}
?>
</div>
<div id="corpo">
<script type="text/javascript">
$(document).ready(function()
{
$("#myTable2").tablesorter();
}
);
</script>
<script type="text/javascript">
onload=function(){
Righello("myTable2");
}
function Righello(IDtabella){
trs=document.getElementById(IDtabella).tBodies[0].rows;
for(i=0;i<trs.length;i++){
tds=trs[i].cells;
trs[i].link=tds[tds.length-1].getElementsByTagName("a")[0].href;
trs[i].title= "Visita " + trs[i].link;
trs[i].style.cursor="pointer";
trs[i].onclick=function(){document.location.href=this.li nk};
trs[i].onmouseover = function(){this.className="corrente";}
trs[i].onmouseout = function(){this.className="";}
}
}
</script>
<h3> PROSSIMI EVENTI </h3>
<?php
// query per l'estrazione dei record
$ev_sql = $data->query("SELECT * FROM ev WHERE evgiorno between CURDATE() AND '2099-01-01' ");
// controllo sul numero di record presenti in tabella
if(mysql_num_rows($ev_sql) > 0){
?>
<table cellpadding="0" cellspacing="1" border="0" id="myTable2" class="tablesorter">
<thead>
<tr>
<th><h3>Data</h3></th>
<th><h3>Regione</h3></th>
<th><h3>Citta</h3></th>
<th><h3>Societá</h3></th>
<th class="nosort" width="57px"><h3>Evento</h3></th>
</tr>
</thead>
<tbody>
<?php
// estrazione dei record tramite ciclo
while($ev_obj = $data->estrai($ev_sql)){
$evid = $ev_obj->evid;
$evnome = stripslashes($ev_obj->evnome);
$evgiorno = date($ev_obj->evgiorno);
$evregione = stripslashes($ev_obj->evregione);
$evcitta = stripslashes($ev_obj->evcitta);
$evpalid = stripslashes($ev_obj->evpalid);
$leggi_tutto = "<a href=\"evento.php?evid=$evid\"> Dettagli </a>\n";
?>
<tr>
<td><?PHP echo "<h5>". $data->format_data($evgiorno) . "</h5>\n"; ?></td>
<td><?PHP echo "<h5>". $evregione . "</h5>\n"; ?></td>
<td><?PHP echo "<h5>". $evcitta . "</h5>\n"; ?></td>
<td><?PHP echo "<h5>". $evpalid . "</h5>\n"; ?></td>
<td> [img]image/find16.png[/img] <?PHP echo "<h5>". $leggi_tutto . "</h5>\n"; ?></td>
</tr>
<?PHP
}
?>
</tbody>
</table>
<?PHP
}else{
// notifica in assenza di record
echo "Nessun evento futuro presente ad oggi !";
}
// chiusura della connessione a MySQL
$data->disconnetti();
?>
</div>