2016-09-07 5 views
-1

リンクをクリックすると関数を実行できるように、クエリのデータをリンク可能またはクリック可能にする方法を教えてください。リンク可能/クリック可能である必要があるデータは日付であり、クリックした後ではそれが機能を実行します。以下はテーブル内のクエリからリンク可能なデータを作成する方法

は、PHPで私のコードです:あなたは、TD内のアンカータグ<a>を開いていないよう

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']); //added 
      echo '<tr class="normalRow"> 
        <td onClick="document.location.href="http://www.yoursite.com";">'.$date.'</a></td> 
        <td border="1">'.$time.'</td> 
        <td border="1">'.$latitude.'</td> 
        <td border="1">'.$longitude.'</td> 
        <td border="1">'.$depth.'</td> 
        <td border="1">'.$magnitude.'</td> 
        </tr>'; 
     } 
    $js_array1 =$the_arraypei;//added    
} 
+0

を試してみようか? –

+0

私はDateの結果をクリック可能にするのに苦しんでいますが、Dateの結果をクリックしたときと同じようにしたいのですが、関数は別のクエリを実行します –

+0

最初の '​​' –

答えて

0

が見えます。

また、PHPのecho文にHTMLを記述しないでください。

<?php 
if (isset($_POST['go'])){ 
    /* Other code */ 
    while($row = mysqli_fetch_array($query)){ 
     /* Loop statements... */ 
     $the_arraypei[] = array($row['Date']); 
?> 
<tr class="normalRow"> 
    <td> 
     <a href="http://www.yoursite.com";"><?php echo $date; ?></a> 
    </td> 
    <td border="1"><?php echo $time ?> </td> 
    <!-- Other tds.... --> 
    <td border="1"><?php echo $magnitude; ?></td> 
</tr> 

<?php } 
    js_array1 = $the_arraypei; //added 
} 
?> 
+0

では、私は$ date onclickを作ることができますか?私は関数のコードをPHPコードの外かPHPコードの中に置くことができましたか?ありがとうございました –

0

私はあなたがそのようなあなたのコードを変更する必要があることを考える:

echo '<tr class="normalRow"><td><a href="http://www.google.it" target="_blank">'.$date.'</a></td><td border="1">'.$time.'</td><td border="1">'.$latitude.'</td><td border="1">'.$longitude.'</td><td border="1">'.$depth.'</td><td border="1">'.$magnitude.'</td></tr>'; 

あなたはjavascriptをせずに新しいウィンドウを開きたい場合。あなたが行うことができますJavaScript関数を実行したい場合はそれ以外の場合:

echo '<tr class="normalRow"><td><button onClick="executeMe()">'.$date.'</button></td><td border="1">'.$time.'</td><td border="1">'.$latitude.'</td><td border="1">'.$longitude.'</td><td border="1">'.$depth.'</td><td border="1">'.$magnitude.'</td></tr>'; 

、ページ上を、あなたは

<script type="text/javascript"> 
    function executeMe() { 
     console.log('Hello World!'); 
    } 
</script> 

を追加する必要がありますhere

*正確に*あなたが立ち往生している
+0

こんにちは@stuzzoのようにボタンを作るのはどうすれば$日付を作ることができますか? onClick ?? –

関連する問題