Visualizzazione dei risultati da 1 a 7 su 7
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    218

    Titolo Colonne Tabella. Si ripetono per ogni row del data base

    Salve a tutti,

    per favore, ho creato una semplicissima tabella:

    http://www.slmty.com/

    Come faccio a far apparire i titoli della tabella <th> solamente una volta. Se notate, si ripetono per ogni row del data base. ( ID Username First Name Last Name Date of Birth Mobile Email Info Photo)

    Ecco il codice che uso nella pagina. Grazie mille in anticipo.


    <?php
    //Variables for connecting to your database.
    //These variable values come from your hosting account.
    $hostname = "slmty.db.10874451.hostedresource.com";
    $username = "slmty";
    $dbname = "slmty";

    //These variable values need to be changed by you before deploying
    $password = "Car4sell!";
    $usertable = "members";
    $id = "id";
    $user = "user";
    $firstname = "firstname";
    $lastname = "lastname";
    $dob = "dob";
    $mobile = "mobile";
    $email = "email";
    $info = "info";
    $photo = "photo";

    //Connecting to your database
    mysql_connect($hostname, $username, $password) OR DIE ("Unable to
    connect to database! Please try again later.");
    mysql_select_db($dbname);

    //Fetching from your database table.
    $query = "SELECT * FROM $usertable";
    $result = mysql_query($query);

    if ($result) {
    while($row = mysql_fetch_array($result)) {

    echo "<table border=1>";
    echo "<tr>";
    echo "<th>"; echo "ID"; echo "</th>";
    echo "<th>"; echo "Username"; echo "</th>";
    echo "<th>"; echo "First Name"; echo "</th>";
    echo "<th>"; echo "Last Name"; echo "</th>";
    echo "<th>"; echo "Date of Birth"; echo "</th>";
    echo "<th>"; echo "Mobile"; echo "</th>";
    echo "<th>"; echo "Email"; echo "</th>";
    echo "<th>"; echo "Info"; echo "</th>";
    echo "<th>"; echo "Photo"; echo "</th>";
    echo "</tr>";

    echo "<tr>";
    echo "<td>"; $name = $row["$id"]; echo "$name
    "; echo "</td>";
    echo "<td>"; $name = $row["$user"]; echo "$name
    "; echo "</td>";
    echo "<td>"; $name = $row["$firstname"]; echo "$name
    "; echo "</td>";
    echo "<td>"; $name = $row["$lastname"]; echo "$name
    "; echo "</td>";
    echo "<td>"; $name = $row["$dob"]; echo "$name
    "; echo "</td>";
    echo "<td>"; $name = $row["$mobile"]; echo "$name
    "; echo "</td>";
    echo "<td>"; $name = $row["$email"]; echo "$name
    "; echo "</td>";
    echo "<td>"; $name = $row["$info"]; echo "$name

    "; echo "</td>";
    echo "<td>"; $name = $row["$photo"]; echo '[img]'.$name.'[/img]'; echo "</td>";

    echo "</tr>";
    echo "</table>";

    }
    }
    ?>

  2. #2
    questa parte
    Codice PHP:
    if ($result) {
     while(
    $row mysql_fetch_array($result)) {

     echo 
    "<table border=1>";
     echo 
    "<tr>";
     echo 
    "<th>"; echo "ID"; echo "</th>";
     echo 
    "<th>"; echo "Username"; echo "</th>";
     echo 
    "<th>"; echo "First Name"; echo "</th>";
     echo 
    "<th>"; echo "Last Name"; echo "</th>";
     echo 
    "<th>"; echo "Date of Birth"; echo "</th>";
     echo 
    "<th>"; echo "Mobile"; echo "</th>";
     echo 
    "<th>"; echo "Email"; echo "</th>";
     echo 
    "<th>"; echo "Info"; echo "</th>";
     echo 
    "<th>"; echo "Photo"; echo "</th>";
     echo 
    "</tr>"
    diventa:

    Codice PHP:
    if ($result) {

     echo 
    "<table border=1>";
     echo 
    "<tr>";
     echo 
    "<th>"; echo "ID"; echo "</th>";
     echo 
    "<th>"; echo "Username"; echo "</th>";
     echo 
    "<th>"; echo "First Name"; echo "</th>";
     echo 
    "<th>"; echo "Last Name"; echo "</th>";
     echo 
    "<th>"; echo "Date of Birth"; echo "</th>";
     echo 
    "<th>"; echo "Mobile"; echo "</th>";
     echo 
    "<th>"; echo "Email"; echo "</th>";
     echo 
    "<th>"; echo "Info"; echo "</th>";
     echo 
    "<th>"; echo "Photo"; echo "</th>";
     echo 
    "</tr>";

     while(
    $row mysql_fetch_array($result)) { 

  3. #3
    Basta lasciare dentro il ciclo solo l'html relativo alle varie righe, portando fuori il resto, così:
    Codice PHP:
    if ($result) {

    echo 
    "<table border=1>";
    echo 
    "<tr>";
    echo 
    "<th>"; echo "ID"; echo "</th>";
    echo 
    "<th>"; echo "Username"; echo "</th>";
    echo 
    "<th>"; echo "First Name"; echo "</th>";
    echo 
    "<th>"; echo "Last Name"; echo "</th>";
    echo 
    "<th>"; echo "Date of Birth"; echo "</th>";
    echo 
    "<th>"; echo "Mobile"; echo "</th>";
    echo 
    "<th>"; echo "Email"; echo "</th>";
    echo 
    "<th>"; echo "Info"; echo "</th>";
    echo 
    "<th>"; echo "Photo"; echo "</th>";
    echo 
    "</tr>";

    while(
    $row mysql_fetch_array($result)) {

    echo 
    "<tr>";
    echo 
    "<td>"$name $row["$id"]; echo "$name
    "
    ; echo "</td>";
    echo 
    "<td>"$name $row["$user"]; echo "$name
    "
    ; echo "</td>";
    echo 
    "<td>"$name $row["$firstname"]; echo "$name
    "
    ; echo "</td>";
    echo 
    "<td>"$name $row["$lastname"]; echo "$name
    "
    ; echo "</td>";
    echo 
    "<td>"$name $row["$dob"]; echo "$name
    "
    ; echo "</td>";
    echo 
    "<td>"$name $row["$mobile"]; echo "$name
    "
    ; echo "</td>";
    echo 
    "<td>"$name $row["$email"]; echo "$name
    "
    ; echo "</td>";
    echo 
    "<td>"$name $row["$info"]; echo "$name

    "
    ; echo "</td>";
    echo 
    "<td>"$name $row["$photo"]; echo '[img]'.$name.'[/img]'; echo "</td>";
    echo 
    "</tr>";

    }

    echo 
    "</table>";


  4. #4
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    218
    Ciao ragazzi e grazie mille per le risposte. ho spostato la riga di codice. ora pero' mi appare solo una parte. Mi appare nella tabella solo il primo row.

    http://www.slmty.com/

  5. #5
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    218
    Qualche suggerimento?

  6. #6
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Originariamente inviato da violaf
    Qualche suggerimento?
    prenderei in considerazione una guida php
    per lo specifico prova cosi:
    Codice PHP:
    if ($result) {

    echo 
    "<table border=1><tr>
    <th>ID</th>
    <th>Username</th>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Date of Birth</th>
    <th>Mobile</th>
    <th>Email</th>
    <th>Info</th>
    <th>Photo </th>
    </tr>"
    ;

    while(
    $row mysql_fetch_array($result)) {

    echo 
    "<tr>";
    echo 
    "<td>".$row["$id"]."</td>";
    echo 
    "<td>".$row["$user"]."</td>";
    echo 
    "<td>".$row["$firstname"]."</td>";
    echo 
    "<td>".$row["$lastname"]."</td>";
    echo 
    "<td>".$row["$dob"]."</td>";
    echo 
    "<td>".$row["$mobile"]."</td>";
    echo 
    "<td>".$row["$email"]."</td>";
    echo 
    "<td>".$row["$info"]."</td>";
    echo 
    "<td>".$row["$photo"]."</td>";
    echo 
    "</tr>";

    }

    echo 
    "</table>";

    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  7. #7
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    218
    grazie mille andrea

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.