2016-05-01 19 views
1

Ich versuche, meine MySQL-Zeilen zu HTML-Bootstrap-Tabelle anzuzeigen. Die Datenbankverbindung funktioniert, die Datenanzeige funktioniert, aber es ist nicht schick, wie ich es möchte. Ich möchte vielleicht vielleicht in ArrayData speichern und dann diese ArrayData in HTML-Tag drucken. Bitte irgendwelche Vorschläge sehr geschätzt. Ich möchte dies am einfachsten und bequemsten für die spätere Bearbeitung tun. PHP-Code-Daten anzuzeigen:bootstrap Anzeige Daten von MySQL in Tabelle

if ($result->num_rows > 0) { 
    // output data of each row 
    while($row = $result->fetch_assoc()) { 
     echo "id: " . $row["id"]. " - Name: " . $row["name"]. " " . $row["lastName"]. "<br>"; /* and so on..*/ 
    } 
} else { 
    echo "0 results"; 
} 

und dies ist mein HTML-Code für Bootstrap

<table class="table table-striped">      
<div class="table responsive"> 

    <thead> 
    <tr> 
     <th>#</th> 
     <th>Name</th> 
     <th>Last Name</th> 
     <th>Number</th> 
     <th>Info</th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr> 
     <th scope="row">1</th> 
     <td>ales</td> 
     <td>king</td> 
     <td></td> 
     <td></td> 
    </tr> 
    <tr> 
     <th scope="row">2</th> 
     <td>love</td> 
     <td>2</td> 
     <td>code</td> 
     <td></td> 
    </tr> 

    </tbody> 
     </div> 
    </table> 

EDIT: Ich will das, aber aus der Datenbank geladen nicht manuell eingegeben :)!

enter image description here

+3

was das erwartete Ergebnis sollte aussehen? Du hast in deiner Frage diesbezüglich nicht viel gesagt. –

+0

sorry Bild hinzugefügt mein schlechtes – swipeales

+0

oh, also Sie suchen nach Paginierung dann, ist es das? –

Antwort

3

kann ein PHP-Schleife verwenden, auf diese Weise

<table class="table table-striped">      
    <div class="table responsive"> 
     <thead> 
      <tr> 
       <th>#</th> 
       <th>Name</th> 
       <th>Last Name</th> 
       <th>Number</th> 
       <th>Info</th> 
      </tr> 
     </thead> 
     <tbody> 
<?php 

.... 

if ($result->num_rows > 0) { 
    // output data of each row 
    while($row = $result->fetch_assoc()) { 


     echo '<tr> 
        <td scope="row">' . $row["id"]. '</td> 
        <td>' . $row["name"] .'</td> 
        <td> '.$row["lastName"] .'</td> 
       </tr>'; 





    } 
} else { 
    echo "0 results"; 
} 
?> 
     </tbody> 
    </div> 
</table> 
+0

thanks works, i have one more question, if i have link in database how could i use swipeales

+0

Link verwenden es funktioniert nicht mit swipeales

+0

i fixed it a href without " " – swipeales

1

ich so etwas tun würde: (aber Sie wirklich einige grundlegende PHP lesen sollte)

<?php 

echo "<table>"; 

// table header 
echo "<tr><th>id</th><th>Name</th><th>Lastname</th></tr>"; 

// output data of each row 
while($row = $result->fetch_assoc()) { 

    echo "<tr><td>".$row["id"]."</td><td>".$row["name"]."</td><td>".$row["lastName"]."</td></tr>"; 
} 

// table footer 

echo "</table>"; 

?> 
+0

thanks works, i have one more question, if i have link in database how could i use swipeales

+0

Same as before: echo "Link "; – Neko

+0

Check out PHP Echo: http://php.net /manual/en/function.echo.php – Neko

Verwandte Themen