Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 19
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2016
    Messaggi
    245

    [PHP] per adesso vincono gli array...

    GLI ERRORI :
    Warning: Illegal string offset 'id' in /web/htdocs/www.help4all.eu/home/php/elenco.php on line 66

    Fatal error: [] operator not supported for strings in /web/htdocs/www.help4all.eu/home/php/elenco.php on line 56

    IL FILE IN QUESTIONE : (sottolineate e in neretto le linee incriminate:dopo un pomeriggio getto la spugna!)

    <?php
    $userid = $_REQUEST['userid'];
    $nomeut = $_REQUEST['nomeut'];
    //echo $userid;
    require('config.php');
    try
    {
    $sql = "SELECT T1.ut_ragsoc as ragsoc,T1.ut_id as id,T1.ut_mail as mail\n"
    . "FROM ut_bro T0 \n"
    . "LEFT JOIN utenti T1 ON T0.bro_id=T1.ut_id\n"
    . "where T0.bro_padre=20\n"
    . "order by T1.ut_id ";
    $result = $pdo->query($sql); // trova 100 101 102
    }
    catch (PDOException $e)
    {
    /* GESTIRE IN MANIERA CORRETTA ERRORE E APRIRE FINESTRA */
    $error = 'Error fetching utenti: ' . $e->getMessage();
    echo $error;
    exit();
    }
    if (!empty($result)) {
    while ($row = $result->fetch())
    {
    $utenti[] = array(
    'id'=> $row['id'],
    'ragsoc'=> $row['ragsoc'],
    'mail'=> $row['mail']);
    }


    foreach ($utenti as $utenti):
    try
    {
    $sql1 = "SELECT T1.ut_ragsoc as ragsoc,T1.ut_id as id,T1.ut_mail as mail\n"
    . "FROM ut_bro T0 \n"
    . "LEFT JOIN utenti T1 ON T0.bro_id=T1.ut_id\n"
    . "where T0.bro_padre=".$utenti['id']."\n"
    . "order by T1.ut_id";
    $result1 = $pdo->query($sql1); // trova 103 104 107 108
    }
    catch (PDOException $e)
    {
    /* GESTIRE IN MANIERA CORRETTA ERRORE E APRIRE FINESTRA */
    $error = 'Error fetching utenti: ' . $e->getMessage();
    echo $error;
    exit();
    }
    if (!empty($result1)) {
    while ($row1 = $result1->fetch())
    {
    $utenti[] = array(
    'id'=> $row1['id'],
    'ragsoc'=> $row1['ragsoc'],
    'mail'=> $row1['mail']);
    $livello1[] = array(
    'id'=> $row1['id']);

    }
    foreach ($livello1 as $livello1):
    try
    {
    $sql2 = "SELECT T1.ut_ragsoc as ragsoc,T1.ut_id as id,T1.ut_mail as mail\n"
    . "FROM ut_bro T0 \n"
    . "LEFT JOIN utenti T1 ON T0.bro_id=T1.ut_id\n"
    . "where T0.bro_padre=".$livello1['id']."\n"
    . "order by T1.ut_id ";
    $result2 = $pdo->query($sql2); // trova 105 106 109
    }
    catch (PDOException $e)
    {
    /* GESTIRE IN MANIERA CORRETTA ERRORE E APRIRE FINESTRA */
    $error = 'Error fetching utenti: ' . $e->getMessage();
    echo $error;
    exit();
    }


    if (!empty($result2)) {
    while ($row2 = $result2->fetch())
    {
    $utenti[] = array(
    'id'=> $row2['id'],
    'ragsoc'=> $row2['ragsoc'],
    'mail'=> $row2['mail']);
    $livello2[] = array( // contiente dati trovati
    'id'=> $row2['id']);
    }
    }
    endforeach;
    }
    endforeach;
    echo "<table style='border: solid 4px white;'>";
    echo "<caption style='font-size: 20px; color:yellow;'>RETE di ".$nomeut."</caption>";
    echo "<tr style='color:white'><th>Utente</th><th>Id</th><th>Mail</th></tr>";

    foreach ($utenti as $utenti):
    echo "<tr style='border:2px solid yellow'>";
    echo "<blockquote>";
    echo "<td style='width: 150px; border: 1px solid yellow;color:white;'>";
    echo "<p>".htmlspecialchars($utenti['ragsoc'], ENT_QUOTES, 'UTF-8')."</p>";
    echo "</td>";
    echo "<td style='width: 150px; border: 1px solid yellow;color:white;'>";
    echo "<p>".htmlspecialchars($utenti['id'], ENT_QUOTES, 'UTF-8')."</p>";
    echo "</td>";
    echo "<td style='width: 150px; border: 1px solid yellow;color:white;'>";
    echo "<p>".htmlspecialchars($utenti['mail'], ENT_QUOTES, 'UTF-8')."</p>";
    echo "</td>" . "\n";
    echo "</blockquote>";
    echo "</tr>";
    endforeach;
    echo "</body></table>";
    }



    ?>

  2. #2
    Codice PHP:
    $livello1 = [];
    if (!empty(
    $result)) { 
    .... 
    ma perchè i \n nelle query?
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2016
    Messaggi
    245
    li mette sqlserver....
    ma io, invece, non ho capito le righe che hai scritto

  4. #4
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Questo foreach ($livello1 as $livello1): non ha senso.
    Ridatemi i miei 1000 posts persi !!!!
    Non serve a nulla ottimizzare qualcosa che non funziona.
    Cerco il manuale dell'Olivetti LOGOS 80B - www.emmella.fr

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2016
    Messaggi
    245
    perchè?
    contiene, nello specifico, 4 elementi per i quali devo eseguire altre query.
    sempre che abbia scritto correttamente....

  6. #6
    Utente di HTML.it
    Registrato dal
    Jul 2016
    Messaggi
    245
    comunque vorrei capire perche quando valorizzo, appunto $livello1, mi da errore....aldila della logica....perchè?

  7. #7
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Guarda il funzionamento del comando foreach. Usi lo stesso nome per l'array e per la variabile che conterrà il risultato e questo non va.
    Ridatemi i miei 1000 posts persi !!!!
    Non serve a nulla ottimizzare qualcosa che non funziona.
    Cerco il manuale dell'Olivetti LOGOS 80B - www.emmella.fr

  8. #8
    +1 alla vista di badaze che scova magagne anche in mezzo a codice non formattato
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  9. #9
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Almeno un altro foreach ha lo stesso problema.
    Mi sa che risolti i due problemi ce ne saranno altri.
    Ridatemi i miei 1000 posts persi !!!!
    Non serve a nulla ottimizzare qualcosa che non funziona.
    Cerco il manuale dell'Olivetti LOGOS 80B - www.emmella.fr

  10. #10
    Utente di HTML.it
    Registrato dal
    Jul 2016
    Messaggi
    245
    allora qualcosa di grossolano mi sfugge :
    $sql = "SELECT T1.ut_ragsoc as ragsoc,T1.ut_id as id,T1.ut_mail as mail\n"
    . "FROM ut_bro T0 \n"
    . "LEFT JOIN utenti T1 ON T0.bro_id=T1.ut_id\n"
    . "where T0.bro_padre=20\n"
    . "order by T1.ut_id ";
    $result = $pdo->query($sql); // trova 100 101 102
    }
    catch (PDOException $e)
    {
    /* GESTIRE IN MANIERA CORRETTA ERRORE E APRIRE FINESTRA */
    $error = 'Error fetching utenti: ' . $e->getMessage();
    echo $error;
    exit();
    }
    if (!empty($result)) {
    while ($row = $result->fetch())
    {
    $utenti[] = array(
    'id'=> $row['id'],
    'ragsoc'=> $row['ragsoc'],
    'mail'=> $row['mail']);
    }


    foreach ($utenti as $utenti):
    codice
    endforeach

    questo ciclo funziona correttamente?

    se si perchè gli altri no?

    $livello1 è un array come $utenti....cosa cambia?
    veramente non capisco e non vedo errore...

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.