Visualizzazione dei risultati da 1 a 5 su 5

Discussione: aiuto codice php mysql

  1. #1

    aiuto codice php mysql

    Salve,
    sono nuovo e inesperto di Php. Perdonatemi sin da ora.
    Ho creato una pagina in php che legge dei dati da un db mysql e ne visualizza il contenuto.
    ho seguito una normale query al DB:
    $result = mysql_query("SELECT * FROM inbox $If ORDER BY ReceivingDateTime desc")

    poi ho creato un:
    while($row = mysql_fetch_array( $result )) {

    dopodichè in una tabella html eseguo:
    echo $row['TextDecoded']; //mostra testo messaggio
    echo "</td><td>";

    una riga per ogni colonna che mi interessa pubblicare.
    Sin qui non ci sono problemi, il problema sorge che nella suddetta tabella inbox ho una colonna dove questi messaggi di testo, a seconda della lunghezza, arrivano spezzati.
    esempio:
    Il testo arriva nella colonna TextDecoded sino a 120 caratteri poi continua nella row successiva e posso riconoscere che è il proseguimento in quanto nella colonna affianco(UDH) ho un numero univoco progressivo tipo 050003010201, 050003010202 ecc.
    Il mio intento era di catturare questa eccezzione e pubblicare questi particolari testi in un unica riga, ovviamente mantenendo sempre quelli che non sono legati dalla colonna col numero progressivo (meno di 120 caratteri circa).

    grazie a tutti per l'aiuto

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2007
    Messaggi
    170
    posta un esempio perche cosi e di difficile comprensione il tuo problema , almeno dal mio punto di vista , esiste un modo per sapere se ce una riga che contiene il proseguimento del messaggio? non sarebbe piu semplice fare in modo da avere il messagio intero nella stessa riga?eliminando il limite dei 120 caratteri?io parlo per mancanza di :-)

  3. #3

    ecco il codice

    ciao nixxo,

    allora, il modo per sapere se c'è il proseguimento del messaggio c'è. Si tratta della colonna UDH della stessa tabella inbox da cui prendo il part number (che sono numeri progressivi univoci di tipo 050003010201, 050003010202, ecc) come vedi nel codice dove faccio un if...
    Purtroppo non posso modificare il limite di 120.
    Ti posto il codice per intero.



    <html>
    <head>
    <style type="text/css">
    <meta name="description" content=gateway." />
    <meta name="keywords" content="opensource gateway software" />


    body {background-color: #CCCCFF}
    h1 {background-color: #FF8000}
    h1 {color: #000066}
    body
    {
    background-image:
    url('logo.gif');
    background-repeat:
    no-repeat;
    background-position:
    right;
    }
    </style>
    </head>
    <body>
    <h1>PROVA</h1>



    Invia Nuovo Messaggio

    <form ACTION=ricerca.php method="POST">
    Ricerca testo: <input type="text" name="term" id="term" />
    <input type="submit" name="search" id="search" SUBMIT value="Search" />


    </form>





    <FORM ACTION=filtro.php method="post2">
    Filtra per data di Oggi:
    <td width=10% align=center bgcolor=#E4E4E4><INPUT TYPE=SUBMIT VALUE="APPLICA">


    </FORM>


    <?//script
    //error_reporting(E_ALL);


    echo "
    ";
    echo "Data di oggi: "; $oggi = print date('d-m-Y');
    // ORIGNALE CHE NON FUNZIONAVA
    function mysql_timestamp_to_human($dt)
    {
    $yr=strval(substr($dt,0,4)); //year
    $mo=strval(substr($dt,4,2)); //month
    $da=strval(substr($dt,6,2)); //day
    $hr=strval(substr($dt,8,2)); //hour
    $mi=strval(substr($dt,10,2)); //minute
    //$se=strval(substr($dt,12,2)); //sec

    return date("d M Y H:i", mktime ($hr,$mi,0,$mo,$da,$yr)).""; //format of displayed date and time
    }




    mysql_connect("localhost", "root", "********") or die(mysql_error()); //connect to mysql
    mysql_select_db("nomedb") or die(mysql_error()); //select database
    if ($Char!="") //check if char was inserted
    $If = "WHERE TextDecoded LIKE '".AddSlashes($Char)."%'"; //if yes, change variable
    else
    $If = ""; //or do nothing



    $result = mysql_query("SELECT * FROM inbox $If ORDER BY ReceivingDateTime desc"); //select data with variable and order it by time and date of the reception

    while($row = mysql_fetch_array( $result )) { //create variable row
    // Print out the contents of each row into a table

    echo "<table border=1 bordercolor=#000046 cellpadding=5 cellspacing=0 style=border-collapse: collapse; font-family: Verdana width=96%>";
    echo "<tr width=5% valign=middle bgcolor=#E4E4E4>";


    echo "</tr>";
    echo "<tr>";
    echo "<td width=0% align=center bgcolor=#E4E4E4><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046>Data Ricezione </font>";
    echo "</td>";
    echo "<td width=3% align=center bgcolor=#E4E4E4><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046>Id</font>";
    echo "</td>";
    echo "<td width=10% align=center bgcolor=#E4E4E4><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046>Numero</font>";
    echo "</td>";

    echo "<td width=65% align=left bgcolor=#E4E4E4><font size=2 face=Verdana, Arial, Helvetica, sans-serif color=#000046>Testo </font>";
    echo "</td>";

    echo "<td width=5% align=center bgcolor=#E4E4E4><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046>Parte </font>";
    echo "</td>";

    echo "<td width=10% align=center bgcolor=#E4E4E4><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046>ELIMINA </font>";
    echo "</td>";

    echo "<td width=5% align=center bgcolor=#E4E4E4><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046>Check </font>";
    echo "</td>";
    echo "</tr>";

    echo "<form action=valuta.php method=post>";


    echo "<tr onMouseOver=this.style.backgroundColor='39C' onMouseOut=this.style.backgroundColor=''><td width=15% align=center ><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046>$row[1]</font></td>";
    $d= $row['ReceivingDateTime']; //create variable for function at begin

    echo "</td>
    <td>";// end and begin of cell
    echo $row['ID'];
    echo "</td><td>";
    echo $row['SenderNumber'] ; //show number
    echo "</td><td>"; //end and begin of cell
    echo $row['TextDecoded']; //show text of the message
    echo "</td><td>";
    if (strlen($row['UDH'])>0) {
    print " P. ";
    echo substr($row['UDH'],strlen($row['UDH'])-2,strlen($row['UDH']));
    }

    echo "<td width=10% align=center><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046><input id=bottone type=submit name=item value=elimina onclick=conferma()></font></td>";


    echo"<td width=5% align=center> <font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046> <input type=\"checkbox\" name=\"item[]\" value=\"$row[ID]\"></td>";

    echo "</table>"; //end of table

    ..............................

    ?>

  4. #4
    Utente di HTML.it L'avatar di carlo2002
    Registrato dal
    Jun 2002
    Messaggi
    2,746
    devi imparare subito che quando posti il codice devi includerlo nei tag [code] o [php]

    questo rende il codice più leggibile e facilita l'ottenimento di una risposta
    Errare humanum est, perseverare ovest

  5. #5

    ecco....

    Codice PHP:
    <html>
    <head>
    <style type="text/css">
    <meta name="description" content=gateway." />
    <meta name="keywords" content="opensource gateway software" />


    body {background-color: #CCCCFF}
    h1 {background-color: #FF8000}
    h1 {color: #000066}
    body
    {
    background-image:
    url('logo.gif');
    background-repeat:
    no-repeat;
    background-position:
    right;
    }
    </style>
    </head>
    <body>
    <h1>PROVA</h1>



    [url="#"]Invia Nuovo Messaggio[/url]

    <form ACTION=ricerca.php method="POST">
    Ricerca testo: <input type="text" name="term" id="term" />
    <input type="submit" name="search" id="search" SUBMIT value="Search" /> 


    </form>





    <FORM ACTION=filtro.php method="post2">
    Filtra per data di Oggi:
    <td width=10% align=center bgcolor=#E4E4E4><INPUT TYPE=SUBMIT VALUE="APPLICA">


    </FORM>


    <?//script
    //error_reporting(E_ALL);


    echo "
    "
    ;
    echo 
    "[b]Data di oggi:[/b] "$oggi = print date('d-m-Y');
    // ORIGNALE CHE NON FUNZIONAVA
    function mysql_timestamp_to_human($dt)
    {
    $yr=strval(substr($dt,0,4)); //year
    $mo=strval(substr($dt,4,2)); //month
    $da=strval(substr($dt,6,2)); //day
    $hr=strval(substr($dt,8,2)); //hour
    $mi=strval(substr($dt,10,2)); //minute
    //$se=strval(substr($dt,12,2)); //sec

    return date("d M Y H:i"mktime ($hr,$mi,0,$mo,$da,$yr)).""//format of displayed date and time
    }




    mysql_connect("localhost""root""********") or die(mysql_error()); //connect to mysql
    mysql_select_db("nomedb") or die(mysql_error()); //select database
    if ($Char!=""//check if char was inserted
    $If "WHERE TextDecoded LIKE '".AddSlashes($Char)."%'"//if yes, change variable
    else
    $If ""//or do nothing



    $result mysql_query("SELECT * FROM inbox $If ORDER BY ReceivingDateTime desc"); //select data with variable and order it by time and date of the reception

    while($row mysql_fetch_array$result )) { //create variable row
    // Print out the contents of each row into a table

    echo "<table border=1 bordercolor=#000046 cellpadding=5 cellspacing=0 style=border-collapse: collapse; font-family: Verdana width=96%>";
    echo 
    "<tr width=5% valign=middle bgcolor=#E4E4E4>";


    echo 
    "</tr>";
    echo 
    "<tr>";
    echo 
    "<td width=0% align=center bgcolor=#E4E4E4><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046>Data Ricezione </font>";
    echo 
    "</td>";
    echo 
    "<td width=3% align=center bgcolor=#E4E4E4><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046>Id</font>";
    echo 
    "</td>";
    echo 
    "<td width=10% align=center bgcolor=#E4E4E4><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046>Numero</font>";
    echo 
    "</td>";

    echo 
    "<td width=65% align=left bgcolor=#E4E4E4><font size=2 face=Verdana, Arial, Helvetica, sans-serif color=#000046>[b]Testo [/b] </font>";
    echo 
    "</td>";

    echo 
    "<td width=5% align=center bgcolor=#E4E4E4><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046>Parte </font>";
    echo 
    "</td>";

    echo 
    "<td width=10% align=center bgcolor=#E4E4E4><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046>ELIMINA </font>";
    echo 
    "</td>";

    echo 
    "<td width=5% align=center bgcolor=#E4E4E4><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046>Check </font>";
    echo 
    "</td>";
    echo 
    "</tr>";

    echo 
    "<form action=valuta.php method=post>";


    echo 
    "<tr onMouseOver=this.style.backgroundColor='39C' onMouseOut=this.style.backgroundColor=''><td width=15% align=center ><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046>$row[1]</font></td>";
    $d$row['ReceivingDateTime']; //create variable for function at begin

    echo "</td>
    <td>"
    ;// end and begin of cell
    echo $row['ID'];
    echo 
    "</td><td>";
    echo 
    $row['SenderNumber'] ; //show number
    echo "</td><td>"//end and begin of cell
    echo $row['TextDecoded']; //show text of the message
    echo "</td><td>";
    if (
    strlen($row['UDH'])>0) {
    print 
    "[b] P. [/b]";
    echo 
    substr($row['UDH'],strlen($row['UDH'])-2,strlen($row['UDH']));
    }

    echo 
    "<td width=10% align=center><font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046><input id=bottone type=submit name=item value=elimina onclick=conferma()></font></td>";


    echo
    "<td width=5% align=center> <font size=1 face=Verdana, Arial, Helvetica, sans-serif color=#000046> <input type=\"checkbox\" name=\"item[]\" value=\"$row[ID]\"></td>";

    echo 
    "</table>"//end of table

    ..............................

    ?>

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.