Visualizzazione dei risultati da 1 a 2 su 2

Discussione: divisione in pagine

  1. #1
    Utente di HTML.it L'avatar di torrone
    Registrato dal
    Apr 2006
    residenza
    Padova
    Messaggi
    1,128

    divisione in pagine

    salve.. vi faccio l'elenco di qualche pagina di un semplicissimo forum che ho..

    per cominciare questà è la struttura del db per il forum

    codice:
    -- --------------------------------------------------------
    
    -- 
    -- Struttura della tabella `forum_lite_main`
    -- 
    
    CREATE TABLE `forum_lite_main` (
      `id` int(11) NOT NULL auto_increment,
      `titolo` varchar(255) NOT NULL default '',
      `img` varchar(255) NOT NULL default '',
      KEY `id` (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
    
    -- 
    -- Dump dei dati per la tabella `forum_lite_main`
    -- 
    
    INSERT INTO `forum_lite_main` (`id`, `titolo`, `img`) VALUES (1, 'prova forum', 'immagine.gif'),
    (2, 'prova 2', '');
    
    -- --------------------------------------------------------
    
    -- 
    -- Struttura della tabella `forum_lite_thread`
    -- 
    
    CREATE TABLE `forum_lite_thread` (
      `id` int(11) NOT NULL auto_increment,
      `topic_id` varchar(255) NOT NULL default '',
      `data` varchar(255) NOT NULL default '',
      `autore` varchar(255) NOT NULL default '',
      `titolo` varchar(255) NOT NULL default '',
      `testo` text NOT NULL,
      KEY `id` (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
    
    -- 
    -- Dump dei dati per la tabella `forum_lite_thread`
    -- 
    
    INSERT INTO `forum_lite_thread` (`id`, `topic_id`, `data`, `autore`, `titolo`, `testo`) VALUES (1, '1', '27/11/2006', 'torrone', 'prova post', 'prova messaggio 1');
    
    -- --------------------------------------------------------
    
    -- 
    -- Struttura della tabella `forum_lite_topics`
    -- 
    
    CREATE TABLE `forum_lite_topics` (
      `id` int(11) NOT NULL auto_increment,
      `forum_id` varchar(255) NOT NULL default '',
      `data` varchar(255) NOT NULL default '',
      `autore` varchar(255) NOT NULL default '',
      `titolo` varchar(255) NOT NULL default '',
      KEY `id` (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
    
    -- 
    -- Dump dei dati per la tabella `forum_lite_topics`
    -- 
    
    INSERT INTO `forum_lite_topics` (`id`, `forum_id`, `data`, `autore`, `titolo`) VALUES (1, '1', '27/11/2006', 'torrone', 'prova post');

    poi c'è index.php (che visualizza le categorie)

    Codice PHP:
    <?php
    # Includo il file di configurazione
    require("config.php");

    # Recupero i forum esistenti
    $query mysql_query("SELECT * FROM forum_lite_main 
        ORDER BY titolo ASC"
    );

    # Stampo il percorso
    echo "Forum";

    echo 
    "<table border=\"1\" cellpadding=\"1\" cellspacing=\"0\"><tr><td colspan=\"2\">[b]<center>Categoria</center>[/b]</td></tr>";

    # Stampo la lista di tutti i Forum
    while($result mysql_fetch_array($query))
    {
        echo 
    "<tr><td width=\"30\" height=\"30\"><img src=\"$result[img]\" \></td><td> <a href=\"forum.php?f=$result[id]\">";
        echo 
    "$result[titolo]</a></td></tr>";
    }

    echo 
    "</table>";
    ?>

    poi c'è forum.php (che visualizza le sezioni delle categorie)

    Codice PHP:
    <?php
    require("config.php");

    # Recupero i topic del forum
    $query = @mysql_query("SELECT * FROM forum_lite_topics
        WHERE forum_id = '" 
    $_GET[f] . "' ORDER BY data ASC");

    # Recupero il titolo del forum per il percorso
    $query2 = @mysql_query("SELECT titolo FROM forum_lite_main
        WHERE id = '" 
    $_GET[f] . "'");

    # Recupero i messaggi nel topic
    $query3 = @mysql_query("SELECT MAX(topic_id) FROM 
        forum_lite_thread"
    );

    $result2 = @mysql_fetch_array($query2);
    $result3 = @mysql_fetch_array($query3);

    # Stampo il percorso
    echo "<a href=\"index.php\">Forum</a> » 
    $result2[titolo]

    "
    ;

    echo 
    "<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\"><tr><td>[b]<center>Discussione</center>[/b]</td><td>[b]<center>Autore</center>[/b]</td></tr>";

    # Stampo a video tutti i topic del Forum selezionato
    while($result = @mysql_fetch_array($query))
    {
        echo 
    "<tr><td><a href=\"thread.php?f=$_GET[f]&t=$result[id]\">";
        echo 
    "$result[titolo]</a></td>";
        echo 
    "<td>[i]<center>$result[autore]</center>[/i]</td></tr>";
    }

    echo 
    "</table>";

    # Recupero il valore più alto di topic_id e lo incremento di uno
    # per creare il link nuovo topic
    $topic_id $result3[topic_id]+1;
    echo 
    "

    [ <a href=\"new.php?f=
    $_GET[f]&t=$topic_id\">";
    echo 
    "Nuovo topic</a> ]";
    ?>

    poi c'è new.php (che è la pagina epr inserire una discussione)

    Codice PHP:
    <?php
    require("config.php");

    # Recupero il titolo del forum dal DB
    $query2 = @mysql_query("SELECT * FROM forum_lite_main
        WHERE id = '" 
    $_GET[f] . "'");
    $result2 = @mysql_fetch_array($query2);

    # Stampo il percorso
    echo "<a href=\"index.php\">Main</a> »";
    echo 
    "<a href=\"forum.php?f=$_GET[f]\">";
    echo 
    "$result2[titolo]</a> » Nuovo topic";

    # Se il valore di cmd è false stampo il form a video
    if ($_POST[cmd] == FALSE)
    {
        echo 
    "<form action=\"$REQUEST_URI\" method=\"post\">\n";
        echo 
    "[b]Titolo[/b]:
    \n"
    ;
        echo 
    "<input type=\"text\" name=\"titolo\">

    \n\n"
    ;
        echo 
    "[b]Nome (o nick)[/b]:
    \n"
    ;
        echo 
    "<input type=\"text\" name=\"autore\">

    \n\n"
    ;
        echo 
    "[b]Messaggio[/b]:
    \n"
    ;
        echo 
    "<textarea name=\"testo\" cols=\"50\" rows=\"5\">";
        echo 
    "</textarea>

    \n\n"
    ;
        echo 
    "<input type=\"hidden\" name=\"cmd\" value=\"add\">\n";
        echo 
    "<input type=\"submit\" value=\"Crea\">\n";
        echo 
    "</form>\n";
    }

    # Se cmd è diverso da false...
    else
    {
        
    # Verifico che tutti i campi necessari siano stati compilati
        
    if ($_POST[titolo] == FALSE OR $_POST[autore] == FALSE
           
    OR $_POST[testo] == FALSE)
        {
            echo 
    "

    Tutti i campi sono obbligatori."
    ;
        }

        
    # Se il controllo è ok salvo tutto nel DB
        
    else
        {
            
    $_POST[testo] = str_replace("\n""
    "
    $_POST[testo]);

            
    mysql_query("INSERT INTO forum_lite_topics
                         VALUES ('',
                                 '" 
    $_GET[f] . "',
                                 '" 
    date("d/m/Y") . "',
                                 '" 
    $_POST[autore] . "',
                                 '" 
    $_POST[titolo] . "')");

            
    mysql_query("INSERT INTO forum_lite_thread
                         VALUES ('',
                                 '" 
    $_GET[t] . "',
                                 '" 
    date("d/m/Y") . "',
                                 '" 
    $_POST[autore] . "',
                                 '" 
    $_POST[titolo] . "',
                                 '" 
    $_POST[testo] . "')");

            echo 
    "

    Il tuo topic è stato inviato con successo."
    ;

        }
    }
    ?>

    poi c'è reply.php (pagina epr rispondere ad un messaggio

    Codice PHP:
    <?php
    require("config.php");

    # Recupero il titolo del forum
    $query2 mysql_query("SELECT titolo FROM forum_lite_main
        WHERE id = '" 
    $_GET[f] . "'");

    # Recupero il titolo del topic
    $query3 mysql_query("SELECT titolo FROM forum_lite_topics
        WHERE forum_id = '" 
    $_GET[f] . "'");

    $result2 mysql_fetch_array($query2);
    $result3 mysql_fetch_array($query3);

    # Stampo il percorso
    echo "<a href=\"index.php\">Main</a> »";
    echo 
    "<a href=\"forum.php?f=$_GET[f]\">$result2[titolo]</a> »";
    echo 
    "<a href=\"thread.php?f=$_GET[f]&t=$_GET[t]\">";
    echo 
    "$result3[titolo]</a> » Rispondi";

    # Se il valore di cmd è false stampo il form a video
    if ($_POST[cmd] == FALSE)
    {
        echo 
    "<form action=\"$REQUEST_URI\" method=\"post\">\n";
        echo 
    "[b]Titolo[/b]: (facoltativo)
    \n"
    ;
        echo 
    "<input type=\"text\" name=\"titolo\">

    \n\n"
    ;
        echo 
    "[b]Nome (o nick)[/b]:
    \n"
    ;
        echo 
    "<input type=\"text\" name=\"autore\">

    \n\n"
    ;
        echo 
    "[b]Messaggio[/b]:
    \n"
    ;
        echo 
    "<textarea name=\"testo\" cols=\"50\" rows=\"5\">";
        echo 
    "</textarea>

    \n\n"
    ;
        echo 
    "<input type=\"hidden\" name=\"cmd\" value=\"add\">\n";
        echo 
    "<input type=\"submit\" value=\"Rispondi\">\n";
        echo 
    "</form>\n";
    }

    # Se cmd è diverso da false...
    else
    {
        
    # Verifico che tutti i campi necessari siano stati compilati
        
    if ($_POST[autore] == FALSE OR $_POST[testo] == FALSE)
        {
            echo 
    "

    Nome e messaggio sono obbligatori."
    ;
        }

        
    # Se il controllo è ok salvo tutto nel DB
        
    else
        {
            
    $_POST[testo] = str_replace("\n""
    "
    $_POST[testo]);
            
    mysql_query("INSERT INTO forum_lite_thread
                         VALUES ('',
                                  '" 
    $_GET[t] . "',
                                 '" 
    date("d/m/Y") . "',
                                 '" 
    $_POST[autore] . "',
                                 '" 
    $_POST[titolo] . "',
                                 '" 
    $_POST[testo] . "')");

            echo 
    "

    Il tuo messaggio è stato inviato con successo."
    ;
        }
    }
    ?>

    poi c'è thread.php (mostra i messaggi postati)

    Codice PHP:
    <?php
    require("config.php");

    # Recupero i messaggi del thread
    $query mysql_query("SELECT * FROM forum_lite_thread
        WHERE topic_id = '" 
    $_GET[t] . "' ORDER BY data ASC");

    # Recupero il titolo del forum
    $query2 mysql_query("SELECT titolo FROM forum_lite_main
        WHERE id = '" 
    $_GET[f] . "'");

    # Recupero il titolo del topic
    $query3 mysql_query("SELECT titolo FROM forum_lite_topics
        WHERE forum_id = '" 
    $_GET[f] . "'");

    $result2 mysql_fetch_array($query2);
    $result3 mysql_fetch_array($query3);

    # Stampo il percorso
    echo "<a href=\"index.php\">Main</a> »";
    echo 
    "<a href=\"forum.php?f=$_GET[f]\">$result2[titolo]</a> »";
    echo 
    "$result3[titolo]";

    # Uso il ciclo while per stampare tutti i messaggi del thread
    while($result mysql_fetch_array($query))
    {
        echo 
    "<hr><div style=\"display: block\">[b]";
        echo 
    "$result[titolo][/b]\n";
        echo 
    "[i]di $result[autore][/i]
    $result[testo]</div>\n";
    }

    # Stampo a video il link per rispondere alla discussione
    echo "<hr>

    <a href=\"reply.php?f=
    $_GET[f]&t=$_GET[t]\">";
    echo 
    "Rispondi</a>";
    ?>

    poi c'è config.php (normale pagina di connessione al db)

    Codice PHP:
    <?php
    # Host
    $mysql['host'] = " ";

    # Username
    $mysql['user'] = " ";

    # Password
    $mysql['pass'] = " ";

    # Nome del DB
    $mysql['name'] = " ";

    # Titolo della nostra Applicazione
    $title "Forum";

    # Funzioni di connessione al nostro DB MySQL
    @mysql_connect($mysql['host'], $mysql['user'], $mysql['pass']);
    @
    mysql_select_db($mysql['name']);

    echo 
    "

    $title</p>\n";
    ?>

    -------------------



    io avrei bisogno di suddividere per pagine la lista delle discussioni (10 per pagina) e dei messaggi in una discussione (sempre 10 o 15 per pagina)... qualcuno mi aiuta, non so come fare.. :berto:


    poi avrei bisogno di una pagina ch mi permettesse di cancellare i messaggi e/o modificare...

    qualche buon anima è disposta ad aiutrami perhcè non so proprio come fare ste cosette!

    grazie!

  2. #2

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.