Visualizzazione dei risultati da 1 a 5 su 5

Discussione: PHP+MYSQL Tabelle

  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2007
    Messaggi
    60

    PHP+MYSQL Tabelle

    Salve a tutti,

    ho un disperato bisogno del vostro aiuto.

    Devo creare un database che serve a cosultare i contatti.

    Sono riuscito a fare tutto tranne che a fare in modo che mi metta il titolo della lista (è a pagina unica).

    Le tabelle sono 2 una che contiene tutti i dati del contatto ed una che serve ad avere il nome della lista a cui fa riferimento.

    Quello che vorrei io è:

    LISTA 1
    contatto1
    contatto2
    contatto3
    ...

    LISTA2
    contatto1
    contatto2
    contatto3
    ...

    Il codice è il seguente:

    Codice PHP:
    <?php
    /*include 'auth.inc.php';

    if ($_SESSION['admin_level'] < 1) {
        header('Refresh: 5; URL=index.php');
        echo '

    [b][/b]You are not authorized for this page.[/b]</p>';
        echo '

    You are now being redirected to the main page. If your browser ' .
            'doesn\'t redirect you automatically, <a href="main.php">click ' .
            'here</a>.</p>';
        die();
    }
    */
    include 'db.inc.php';

    $db mysql_connect(MYSQL_HOSTMYSQL_USERMYSQL_PASSWORD) or 
        die (
    'Unable to connect. Check your connection parameters.');
    mysql_select_db(MYSQL_DB$db) or die(mysql_error($db));
    ?>
    <html>
     <head>
      <title>contatti database</title>
      <style type="text/css">
       th { background-color: #999;}
       .odd_row { background-color: #EEE; }
       .even_row { background-color: #FFF; }
      </style>
     </head>
     <body>


     <table style="width:100%;">
      
    <?php

    $query 
    'SELECT * FROM contatti, Lista WHERE contatti.Lista_id = Lista.Lista_id';
     
    $result mysql_query($query$db) or die (mysql_error($db));

    $odd true;
    while (
    $row mysql_fetch_assoc($result)) {
        echo 
    '<table style="width:100%;">
          <tr>
           <th colspan="2">'
    $row['Lista'] .'[url="contatti.php?action=add"][ADD][/url]</th>
          </tr>'
    ;  
        echo (
    $odd == true) ? '<tr class="odd_row">' '<tr class="even_row">';
        
    $odd = !$odd
        echo 
    '<td style="width:75%;">'
        echo 
    $row['Nome'];
        echo 
    '</td>';
         echo 
    '<td style="width:75%;">'
        echo 
    $row['Lista'];
        echo 
    '</td><td>';
        echo 
    ' [url="contatti.php?action=edit&id=' $row['contatti_id'] . '"] [EDIT][/url]'
        echo 
    ' [url="delete.php?type=contatti&id=' $row['contatti_id'] . '"] [DELETE][/url]';
        echo 
    '</td></tr>';
    }

    ?>
      </table>
     </body>
    </html>

  2. #2
    Utente di HTML.it L'avatar di clasku
    Registrato dal
    Aug 2006
    Messaggi
    3,197
    $row['Lista']

    ma Lista è anche il nome del campo oltre che della tabella?

  3. #3
    Utente di HTML.it
    Registrato dal
    Nov 2007
    Messaggi
    60
    Si.

    Io riesco solamente a farlo scrivere sopra ad ogni contatto, ma non so come fare per metterlo sopra ad ogni lista e basta, del tipo

    LISTA 1
    contatto1
    LISTA 1
    contatto2
    LISTA 1
    contatto3
    LISTA1
    ...

    LISTA2
    contatto1
    LISTA2
    ...

  4. #4
    Utente di HTML.it L'avatar di clasku
    Registrato dal
    Aug 2006
    Messaggi
    3,197
    prova così, se ho colto quello che ti serve
    Codice PHP:
    $odd true

    $lista ""

    while (
    $row mysql_fetch_assoc($result)) { 

        if (
    $lista !== $row['Lista']) {
           
    $titolo_lista $row['Lista'];
           
    $lista $titolo_lista;
        }    
        else {
           
    $titolo_lista "";
        }
        echo 
    '<table style="width:100%;"> 
          <tr> 
           <th colspan="2">'
    $titolo_lista .'[url="contatti.php?action=add"][ADD][/url]</th> 
          </tr>'
    ;   
        echo (
    $odd == true) ? '<tr class="odd_row">' '<tr class="even_row">'
        
    $odd = !$odd;  
        echo 
    '<td style="width:75%;">';  
        echo 
    $row['Nome']; 
        echo 
    '</td>'
         echo 
    '<td style="width:75%;">';  
        echo 
    $row['Lista']; 
        echo 
    '</td><td>'
        echo 
    ' [url="contatti.php?action=edit&id=' $row['contatti_id'] . '"] [EDIT][/url]';  
        echo 
    ' [url="delete.php?type=contatti&id=' $row['contatti_id'] . '"] [DELETE][/url]'
        echo 
    '</td></tr>'


  5. #5
    Utente di HTML.it
    Registrato dal
    Nov 2007
    Messaggi
    60
    Grazie.

    Il problema comunque ho visto che era anche nel tr che comunque lo ripeteva ugualmente anche senza titolo, togliendo quello ora è perfetto.

    Grazie mille a buon rendere.

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.