I am trying to add the functionality to show the details of some elements on click.
<table class = "tabella_spettacolo">
<thead>
<tr style = "color:#00a3cc">
<td>Evento</td>
</tr>
</thead>
<tbody>
<div class = "opacita_spettacolo"> </div>
<?php
$queryText2 = ("SELECT NomeEvento FROM eventi WHERE categoria = 'concerto' and DataOra >= current_date ");
$query2=$dbCon->query($queryText2);
while($cicle=$query2->fetch_array()){
echo "
<tr>
<td>
<a class = 'eventi' href = './evento.php'>" . $cicle[0] . "</a>
</td>
</tr>";
}
$dbCon->close();
?>
</tbody>
</div>
</table>
I need that, for example, when you 'click' on an element of the table, the site redirects to another page with the details of that element.
Well, I think you can handle it in different ways. Depending on your needs and creativity.
If your row data in your database has an ID
Render the ID in your element:
Suppose that $cicle[0]
is your ID now.
<a class = 'eventi' href = './evento.php?ID='+'$cicle[0]'>" . $cicle[0] . "</a>
It will render a link liks this so when you click it you will go to the other page and you can require the URL parameters.
<a target=_blank href="https://www.w3schools.com?id=12">Visit W3Schools.com!</a>
Require your ID $_GET["ID"]
and "SELECT NomeEvento FROM eventi WHERE ID = $_GET["ID"]"
I'm NOT a PHP expert but I think you can get the essence of my suggestion. Anyways, let me know if it's not what you are looking for. Thanks :)
var link="https://www.google.com/search?q=";
var arr=[ "Ford", "BMW", "Fiat" ];//this array is your php/mysql return array
var x = "";
for (i in arr) {
$("#tableBody").append("<tr><td>"+i+"</td><td><a href='"+link+arr[i]+"' target='_blank'>"+arr[i] + "</a></td></tr>");
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table >
<tr>
<th>Item No</th>
<th>Car</th>
</tr>
<tbody id="tableBody">
</tbody>
</table>
</div>
your code is
<a class = 'eventi' href = './evento.php'>" . $cicle[0] . "</a>
you have to do like this
$cicle[0]
is may be your eventName OR eventId
<a class = 'eventi' href = './evento.php?ID='+'$cicle[0]'>" . $cicle[0] . "</a>