Visualizzazione risultati 1 fino 8 di 8

Discussione: Paginazione guestbook php

  1. #1
    Guest

    Predefinito Paginazione guestbook php

    Ciao a tutti^^
    Volevo incrementare con paginazione un guestbook che ho realizzato con un tutorial trovato in rete, premetto che è il primo "lavoro" che faccio in php e se non fosse stato per il tutorial assolutamente semplice non credo sarei riuscita a combinare gran chè, ora è una settimana che cerco di dividere in pagine la visualizzazione dei messaggi, dopo aver letto un mare di tutorial in rete sui vari metodi x fare una paginazione dei dati di mysql sono riuscita a capire come si crea una paginazione, il problema è che non riesco ad integrarla con il codice del guestbook.
    ecco la pagina prova --> http://penelopesito.altervista.org/guest.php
    Il guest è suddiviso in
    tabella dati.sql
    fmysql.php
    guest.php

    la tabella dati è così composta:
    Codice:
    id int(11) NOT NULL auto_increment,
    nome varchar(100) NOT NULL default '',
    email varchar(150) NOT NULL default '',
    message longtext NOT NULL default '',
    data varchar(100) NOT NULL default '',
    www varchar(150) NOT NULL default '',
    PRIMARY KEY (id)
    )
    ************************
    file fmysql.php //questo credo sia il file da dover modificare:

    Codice:
    <?php
    
    function closeConnect($conn)
    {
        mysql_close($conn);
    }
    
    function connessione($database)
    {
    	$conn=mysql_connect("localhost","root","") 
    	or die("Connessione non riuscita: ".mysql_error());
    	mysql_select_db($database) or  die("Selezione del database non riuscita");
    	
    	
    	return $conn;
    }
    
    
    function mysql_list_all($table,$con)
    {
         $result=mysql_query("SELECT * FROM $table order by id desc;",$con);
    	 while($row=mysql_fetch_array($result,MYSQL_ASSOC))
    	 
    	 {
    		 $ret[]=$row;	 
    	 }
    	 return $ret;
    }
    
    function lista($value)
    {
    	print("<TABLE border=0 cellpadding=0 cellspacing=4 width=100%>");
    	foreach($value as $key=>$val)
    	{
    		{
    			print("<TR height=10><TD align=right valign=middle class=row4><SPAN class=genmed><IMG SRC='images/data.png' WIDTH='16' HEIGHT='16' BORDER=0 ALT='Lasciato il ".$val["data"]."'>&nbsp;&nbsp;</SPAN></TD></TR>");
    			if($val["www"]!="http://" && $val["www"]!="")
    			{
    				print("<TR><TD class=row1><SPAN class=genmed>&nbsp;<A HREF='".$val["www"]."' target=void class=genmed><IMG SRC='images/home.png' WIDTH=16 HEIGHT=16 BORDER=0 alt='Il mio sito'></A>");
    			}
    			else print("<TR><TD class=row1><SPAN class=genmed>");
    			if($val["email"]!="" && $val["email"]!="EMAIL" && $val["email"]!="email")
    			{
    				print("&nbsp;&nbsp;<A HREF='mailto:".$val["email"]."' class=genmed><IMG SRC='images/emailsi.png' WIDTH='16' HEIGHT='16' BORDER=0 ALT='E-mail'></A><B>&nbsp;Nikname:</B> ".$val["nome"]."</SPAN></TD></TR>");
    			}
    			else
    			{
    				print("&nbsp;&nbsp;<IMG SRC='images/emailno.png' WIDTH='16' HEIGHT='16' BORDER=0 ALT='No E-mail'><B>&nbsp;Nikname:</B> ".$val["nome"]."</SPAN></TD></TR>");
    			}
    			print("<TR><TD valign=top class=row3><SPAN class=genmed><IMG SRC='images/mex.png' WIDTH='16' HEIGHT='16' BORDER=0><B>&nbsp;Messaggio:</B> ".$val["message"]."<br><hr color='#677838' width='98%'></SPAN></TD></TR>");
    		}
    	}	
    	print("</TABLE>");
    }
    
    
    
    function mysql_insert($value,$data,$table,$conn)
    {
    	$query=("INSERT INTO $table (nome,email,message,data,www) VALUES ('".$value["nome"]."','".$value["email"]."','".$value["message"]."','".$data."','".$value["www"]."');");
    	$result=mysql_query($query);
    }
    
    function esiste($arr,$table,$conn)
    {
    	$query = "SELECT * FROM ".$table." WHERE nome='".$arr["nome"]."' AND email='".$arr["email"]."' AND message='".$arr["message"]."' AND www='".$arr["www"]."';";
    	$res = mysql_query($query, $conn);
    	while($row = mysql_fetch_array($res, MYSQL_ASSOC))
    		$ret = $row;
    	if(is_array($ret))
    		return true;			#  funzione che mi ritorna true se esiste già un mex uguale
    	else
    		return false;
    	
    }
    ?>
    ****************************
    Nel file guest.php che in pratica è la home del guestbook c'è il form per inviare i messaggi
    e i tag che permettono la visualizzazione di quelli inseriti vi posto la parte dove viene richiamato
    il file fmysql.php

    Codice:
    <TABLE class=tableborder1 cellpadding=0 cellspacing=0 width='100%'>
    <TR>
    <TD valign=top class=row2>
    <?php
    include_once(GUEST_DIR."/fmysql.php");
    $conn = connessione("my_penelopesito");
    $query = mysql_list_all("dati",$conn);
    if($query!=null)
    {
    lista($query);
    }
    closeConnect($conn);
    ?>
    </TD>
    </TR>
    </TABLE>
    ************************************************
    come ho detto ho fatto un mare di prove, ho capito come si fanno le richieste ai dati di una tabella mysql ma non riesco ad integrare il codice con quello del guestbook^^
    ecco una prova -->http://penelopesito.altervista.org/prova5.php
    Spero di esser stata chiara e possiate aiutarmi a risolvere
    Grazie
    Ultima modifica di svacant : 30-08-2009 alle ore 10.43.21 Motivo: sistemato codici scusate poco pratica forum^^

  2. #2
    Guest

    Predefinito

    Prima di aiutarti fammi un favore, racchiudi il codice nei tag appositi, grazie.

  3. #3
    Guest

    Predefinito

    Scusate ma ho pasticciato peggio nell'edita non da tutti i tag, ho provato a scrivere io [CODICE] ma nulla mi spiace

  4. #4
    Guest

    Predefinito

    Va bene, ma il tag è [CODE] non [CODICE], ritorniamo on topic.

  5. #5
    Guest

    Predefinito

    Nessuno mi sa dare una mano? Scusate l'insistenza io ho riprovato a cercare una soluzione ma nulla^^ Grazie

  6. #6
    Guest

    Predefinito

    Arieccomi chiedo scusa x up ma non mi risponde nessuno...

  7. #7
    Guest

    Predefinito

    Ciao ragazzi ho fatto un po' di "esercizi" con php per riuscire a fare sta benedetta paginazione e sono riuscita a realizzare un sistema di news per il sito completo^^
    ecco --> http://penelopesito.altervista.org/n...aginazione.php
    funziona benissimo ho utilizzato questo codice:
    Codice:
    <html>
    <head>
    <title>...Il telaio news</title>
    <LINK HREF="stile.css" type="text/css" rel="stylesheet" >
    </head>
    <body>
    
    
    <?php
    // connessione al database
    mysql_connect("localhost","*********","********") or die("Connessione fallita !");
    
    // selezione del DB
    mysql_select_db("*********") or die("Selezione del DB fallita !");
    $page = (!isset($_GET['page']))? 1 : $_GET['page'];
    $prev = ($page - 1);
    $next = ($page + 1);
    
    /*Setto il numero massimo di record per pagina */
    $max_results = 3;
    
    /* Mi calcolo l'offset */
    $from = (($page * $max_results) - $max_results);
    
    /*eseguo la query per recuperare il numero di dati presente nel mio db*/
    
    $result = mysql_query("select * FROM  news ORDER BY id Desc");
    
    $total_results = mysql_num_rows($result);
    
    $total_pages = ceil($total_results / $max_results);
    
    /* Creo il link "PREV" */ 
    if($page > 1) 
    { 
    $pagination .="<a href=provapaginazione.php?page=".$prev.">Prec&nbsp; </a>"; 
    }
    
    /*Eseguo il ciclo per visualizzare tutte le pagine che mi servono. */
    for($i =1; $i <= $total_pages; $i++)
       {
          if(($page) == $i)
           {
             $pagination .= $i;
           }
              else
               {
                  $pagination .= "<a href=provapaginazione.php?page=".$i.">| $i&nbsp;</a>";
                }
        }/*END FOR*/
    
    /* Stampo il prossimo link */
        if($page < $total_pages)
         {
           $pagination .= "<a href=provapaginazione.php?page=".$next."> &nbsp;Next</a>";
         }
    
    /*eseguo la query con i parametri $from e $total_results per la paginazione*/
    
    $result=mysql_query("select * FROM news ORDER BY id Desc LIMIT $from, $max_results ");
    
    while ($i = mysql_fetch_array($result))
    /* Ora visualizziamo le news */ 
        echo "<table>
    	<tr>
    		<td><table class=t1 cellpadding=5 cellspacing=0 width=600>
    	<tr>
    		<td class=c1>
    <TABLE class=t2 cellpadding=3 cellspacing=0 width=100%> 
        <TR> 
            <TD class=c2 width=515><img border=0 src='images/B32.png' width=10 height=10> $i[title]</TD> 
            <TD class=c2 width=70><img border=0 src='images/B25.png' width=10 height=10> $i[date]</TD> 
        </TR> 
        <TR> 
            <TD width=642 colspan=2><img border=0 src='images/Z35.png' width=10 height=10> $i[news]</TD> 
        </TR> 
        <TR> 
            <TD width=515>by $i[author] <img border=0 src='images/tinyblackcat.gif' width=17 height=15></TD> 
            <TD class=c2 width=123>&nbsp;</TD> 
        </TR> 
        </TABLE></td>
    	</tr>
    </table></td>
    	</tr>
    	<tr>
    		<td height=3></td>
    	</tr>
    </table>"; 
    "<br>";
    
    echo "<table class=t3 width=600>
    	<tr>
    		<td>$pagination<br><br></td>
    	</tr>
    </table>";
    ?>
    
    </body>
    
    </html>
    Non riesco però a fare la stessa cosa con il guest, più che altro non so come rendere linkabile i link e le mail la table dei messaggi è fatta cosi:
    Codice:
    <?php
    
    function closeConnect($conn)
    {
        mysql_close($conn);
    }
    
    function connessione($database)
    {
    	$conn=mysql_connect("localhost","root","") 
    	or die("Connessione non riuscita: ".mysql_error());
    	mysql_select_db($database) or  die("Selezione del database non riuscita");
    	
    	
    	return $conn;
    }
    
    
    function mysql_list_all($table,$con)
    {
         $result=mysql_query("SELECT * FROM $table order by id desc;",$con);
    	 while($row=mysql_fetch_array($result,MYSQL_ASSOC))
    	 
    	 {
    		 $ret[]=$row;	 
    	 }
    	 return $ret;
    }
    
    function lista($value)
    {
    	print("<TABLE border=0 cellpadding=0 cellspacing=4 width=100%>");
    	foreach($value as $key=>$val)
    	{
    		{
    			print("<TR height=10><TD align=right valign=middle class=row4><SPAN class=genmed><IMG SRC='images/data.png' WIDTH='16' HEIGHT='16' BORDER=0 ALT='Lasciato il ".$val["data"]."'>&nbsp;&nbsp;</SPAN></TD></TR>");
    			if($val["www"]!="http://" && $val["www"]!="")
    			{
    				print("<TR><TD class=row1><SPAN class=genmed>&nbsp;<A HREF='".$val["www"]."' target=void class=genmed><IMG SRC='images/home.png' WIDTH=16 HEIGHT=16 BORDER=0 alt='Il mio sito'></A>");
    			}
    			else print("<TR><TD class=row1><SPAN class=genmed>");
    			if($val["email"]!="" && $val["email"]!="EMAIL" && $val["email"]!="email")
    			{
    				print("&nbsp;&nbsp;<A HREF='mailto:".$val["email"]."' class=genmed><IMG SRC='images/emailsi.png' WIDTH='16' HEIGHT='16' BORDER=0 ALT='E-mail'></A><B>&nbsp;Nikname:</B> ".$val["nome"]."</SPAN></TD></TR>");
    			}
    			else
    			{
    				print("&nbsp;&nbsp;<IMG SRC='images/emailno.png' WIDTH='16' HEIGHT='16' BORDER=0 ALT='No E-mail'><B>&nbsp;Nikname:</B> ".$val["nome"]."</SPAN></TD></TR>");
    			}
    			print("<TR><TD valign=top class=row3><SPAN class=genmed><IMG SRC='images/mex.png' WIDTH='16' HEIGHT='16' BORDER=0><B>&nbsp;Messaggio:</B> ".$val["message"]."<br><hr color='#677838' width='98%'></SPAN></TD></TR>");
    		}
    	}	
    	print("</TABLE>");
    }
    
    
    
    function mysql_insert($value,$data,$table,$conn)
    {
    	$query=("INSERT INTO $table (nome,email,message,data,www) VALUES ('".$value["nome"]."','".$value["email"]."','".$value["message"]."','".$data."','".$value["www"]."');");
    	$result=mysql_query($query);
    }
    
    function esiste($arr,$table,$conn)
    {
    	$query = "SELECT * FROM ".$table." WHERE nome='".$arr["nome"]."' AND email='".$arr["email"]."' AND message='".$arr["message"]."' AND www='".$arr["www"]."';";
    	$res = mysql_query($query, $conn);
    	while($row = mysql_fetch_array($res, MYSQL_ASSOC))
    		$ret = $row;
    	if(is_array($ret))
    		return true;			#  funzione che mi ritorna true se esiste già un mex uguale
    	else
    		return false;
    	
    }
    ?>
    Per favore help me grazie^^

  8. #8
    Guest

    Predefinito

    Grazie risolto ^_^

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •