2017-07-25 19 views
0

私の動的表の中の情報を誰かがクリックしたときに取得しようとしているので、列単位で読み込んでデータを抽出して表示することができますテキストボックスに保存します。私はこの言語に新しいので、それを行う方法を知らない、あなたが助けることを願っています。現時点で何をしているのかは、私のデータベースからデータを取り出し、それを使って動的テーブルを作成することです。 私はすでにいくつかのことを試みましたが、どれもうまくいきませんでしたので、失敗したすべての試行をここに貼り付けるつもりはありません。多くの人々はそれがmysqlの私がMysqli_にそれを更新しているとの問題を抱えていたので、 はこれが(私のコードです:PHPでhtml行(テーブル内)からデータを取得するには

if (($result)||(mysqli_errno == 0)) 
{ 
echo "<table cellspacing='0' cellpadding='0' border='0' width='126%'> 
<tr> 
    <td> 
    </table> 
<div style='width:450; height:350px; overflow:auto;'> 
<table cellspacing='0' cellpadding='1' border='1' width='380px'> 
    <tr style='color:white;background-colorgrey'>"; 
if (mysqli_num_rows($result)>0) 
{ 
     //loop thru the field names to print the correct headers 
     $i = 0; 
     while ($i < mysqli_num_fields($result)) 
     { 
      $fetch = mysqli_fetch_field_direct($result, $i); 
      echo "<th>". $fetch->name . "</th>"; 
      $i++; 
    } 
//display the data 
while ($rows = mysqli_fetch_assoc($result)) 
{ 
    echo "<tr>"; 
    foreach ($rows as $data) 
    { 
    echo "<td align='center' width='400px'>". $data . "</td>"; 
    } 
    echo"</tr>"; 
} 
}else{ 
    echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>"; 
} 
    echo "</table></div>";     
+0

この行の終了タグは次のとおりです。 ";'この行の終了タグは次のとおりです。 ? – Virb

+1

出力がありますか?BTW:mysql_ *は既に廃止されていますが、代わりにmysqli_ *を使用してください! – Bernhard

+0

trを閉じるのを忘れてしまいました!^^ @Virb – JuanjoC

答えて

0

答えに興味がある人のために、私は、要素(変数「ID」の店舗をそれを考え出しました

 <table cellspacing='0' cellpadding='0' border='0' width='126%'> 
    <tr> 
    <td> 
    </table> 
<div style='width:450; height:350px; overflow:auto;'> 
<table style="display: table-row" class='prueba' cellspacing='0'    cellpadding='1' border='1' width='380px'> 
    <tbody> 
    <tr style='color:white;background-colorgrey'> 

    <?php 

    ///******/// 
    ///CONECTION AND QUERY INFO WOULD GO HERE/// 
    ///******/// 

    if (($result)||(mysqli_errno == 0)) 
{ 

    if (mysqli_num_rows($result)>0) 
    { 
     //loop thru the field names to print the correct headers 
     $i = 0; 
     echo "<th><a>Check</a></th>"; 
     while ($i < mysqli_num_fields($result)) 
     { 
      $fetch = mysqli_fetch_field_direct($result, $i); 
    echo "<th><a>". $fetch->name . "</a></th>"; 
    $i++; 
    } 
    //display the data 
    while ($rows = mysqli_fetch_assoc($result)) 
    { 
    echo "<tr onClick='Content(this)'>"; 
    foreach ($rows as $data) 
    { 
    echo "<td align='center' width='400px'><a>". $data . "</a></td>"; 
    } 
    echo"</tr>"; 
    } 
    }/*else{ 
    echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>"; 
    }*/ 

    }else{ 
    echo "'Error in running query :'. mysqli_error()"; 
    }  

    //echo "<style>"; 

/*echo "</tr></table></td></tr><tr><td> 
     <table min-width='400px' cellspacing='0' cellpadding='1'  border='1'>";*/ 

echo "</table></div>"; 
echo "<script> 
    function Content(elem){ 
     elem.style.backgroundColor = 'red'; 

     var id = $(elem).find('td:eq(0)').text(); 
     alert(id);} 
     </script>"; 
    ?> 
    </p> 
関連する問題