2017-07-25 1 views
0

Ich versuche, die Informationen in meiner dynamischen Tabelle zu erhalten, wenn jemand darauf klickt, so kann ich Spalte für Spalte lesen und die Daten extrahieren, um es dann zu zeigen in einem Textfeld. Ich weiß nicht, wie man es macht, seit ich neu in diesen Sprachen bin, hoffe du kannst helfen. Was ich gerade mache ist, die Daten aus meiner Datenbank zu extrahieren und die dynamische Tabelle damit zu erstellen. Ich habe schon ein paar Dinge ausprobiert, aber keiner von ihnen hat funktioniert, also werde ich nicht alle gescheiterten Versuche hier einfügen. Dies ist mein Code (da viele Leute Probleme hatten, mit ihm mysql sein ich es Mysqli_ aktualisiert:Wie man Daten aus einer HTML-Zeile (in einer Tabelle) mit PHP

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

Wo der schließende Tag dieser Linie ist '"; ' ? – Virb

+1

Haben Sie eine Ausgabe? BTW: mysql_ * ist bereits veraltet. Verwenden Sie stattdessen mysqli_ *! – Bernhard

+0

Forgot Schließen der tr! Scheint gut zu funktionieren tho ^^. @Virb – JuanjoC

Antwort

0

Für alle Interessierten in der Antwort, dachte ich es aus (die Variable „id“ speichert das Element aus der Spalte "0" aber Sie können die 0 ändern verschiedene Spalten zu bekommen):

 <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> 
Verwandte Themen