how to make a linkable data from a query in a table

How can i make the data from my query linkable/ clickable so that i can run a function when i click it. The data that need to be linkable /clickable is the date and after clicking it will run a function.

Below is my code in php

[php]<?php

if (isset($_POST[‘go’])){
if (((!empty($_POST[‘from’])&&!empty($_POST[‘to’])))&&((!empty($_POST[‘from’])&&!empty($_POST[‘to’])))){
$from = $_POST[‘from’];
$to = $_POST[‘to’];
$from =explode(’/’,$from);
$from = “$from[2]-$from[0]-$from[1]”;
$to = explode (’/’,$to);
$to = “$to[2]-$to[0]-$to[1]”;
$query= mysqli_query($con,“SELECT Date, Time, Latitude,Longitude,Depth,Magnitude FROM bulletin WHERE Date between ‘$from’ and ‘$to’;”);
$the_array = array();
while($row = mysqli_fetch_array($query)){
$date = $row[‘Date’];
$time = $row[‘Time’];
$latitude= $row[‘Latitude’];
$longitude= $row[‘Longitude’];
$depth =$row[‘Depth’];
$magnitude = $row[‘Magnitude’];
$the_arraypei[] = array($row[‘Date’] );
echo ‘

<td onClick=“document.location.href=“http://www.yoursite.com”;”>’.$date.’’.$time.’ ’.$latitude.’ ’.$longitude.’ ’.$depth.’ ’.$magnitude.’ ’;
}
        $js_array1 =$the_arraypei;

                }



    ?>[/php]

Drop the field into an anchor tag, {field}

hi will it work even its inside a php ?

It will, just depends how you go about doing so.

hi sir how can i make this work

<a href="#" onClick="javascript.functiontoget$date();">$date</a>

the $date is the result of my search query below is my loop

while($row = mysqli_fetch_array($query)){ $date = $row['Date']; echo '<tr class="normalRow"><td><a href="#" onClick="javascript.functiontoget$date();">$date</a></td></tr>;' }

Why is the variable value part of the JavaScript function name?

thats not the real name of the function i just place it so that youll get the purpose of the function
that function will get the value of that $date (the one that was click) and will use it as a parameter of a new query.
so inshort when i click the value of the date the system will run another query using the value of the date
sorry still newbie in coding

First and best piece of advice I can give you starting out, figure out exactly what you want to happen BEFORE you start writing any code to do it.

[php]
while($row = mysqli_fetch_array($query)){
echo “

<a href=’#’ onClick=‘javascript.functiontoget(’{$row[‘Date’]}’);’>{$row[‘Date’]}”;
}[/php]

You will want something like that.

were is the best place to place the functrion inside the php code or outside…

Huh?

hi sir i tried use what you gave me
this one

echo '<tr class="normalRow"><td id="date2"><a href="#" onClick="functiontoget(\'$date\');">'.$date.'</a></td></tr>';[/code]

and i created a function

[code] <script>
  function functiontoget($date) { 
	var x = document.getElementsByTagName($date)[0].textContent;
	document.getElementById("demo").innerHTML = x;
}
  </script>
  
  <p id="demo"></p>

but when i click the date no value was shown in my page

Your version is different than mine.

Sponsor our Newsletter | Privacy Policy | Terms of Service