Visualizzazione dei risultati da 1 a 8 su 8
  1. #1
    Utente di HTML.it L'avatar di gianiaz
    Registrato dal
    May 2001
    Messaggi
    8,027

    UPDATE mysql, concatenare stringa a campo

    Ciao, vorrei fare una procedura di log per le sessioni che avvengono su un sito, vorrei registrare da dove sono passati gli utenti, e mi basterebbe un semplice campo text dove accodare di volta in volta il nome dell'area visitata.

    La domanda è la seguente:

    Posso con una query accodare una stringa ad un campo senza far intervenire php? (cioè evitando di 1.leggere il contenuto del campo.2.accodare la mia stringa.3.fare una query di update).

    ciao e grazie

  2. #2
    codice:
    update tabella
    set campo = concat(campo,' ','$stringa')
    where ....
    tra le virgolette mettici un divisore o uno spazio...



    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  3. #3
    Utente di HTML.it L'avatar di gianiaz
    Registrato dal
    May 2001
    Messaggi
    8,027
    cercando con google avevo trovato :

    codice:
    UPDATE logs SET areevisitate = CONCAT(areevisitate,'valore')
    tu hai messo 3 argomenti invece, puoi spiegarmi o darmi un link per capire la sintassi di concat?

    sto cercando sul sito di mysql ma lo odio sempre di +, non trovo mai nulla

    cia

  4. #4
    Originariamente inviato da gianiaz
    cercando con google avevo trovato :

    codice:
    UPDATE logs SET areevisitate = CONCAT(areevisitate,'valore')
    tu hai messo 3 argomenti invece, puoi spiegarmi o darmi un link per capire la sintassi di concat?

    sto cercando sul sito di mysql ma lo odio sempre di +, non trovo mai nulla

    cia
    non ha messo 3 argomenti, ma due cose come secondo argomento:

    primo argomento: campo originale
    secondo argomento (quello che si aggiunge): separatore + valore da concatenare



  5. #5
    Originariamente inviato da }gu|do[z]{®©
    non ha messo 3 argomenti, ma due cose come secondo argomento:

    primo argomento: campo originale
    secondo argomento (quello che si aggiunge): separatore + valore da concatenare

    Guidozz la croatia ti ha fatto bene...
    CONCAT(str1,str2,...)

    Returns the string that results from concatenating the arguments. Returns NULL if any argument is NULL. May have one or more arguments. If all arguments are non-binary strings, the result is a non-binary string. If the arguments include any binary strings, the result is a binary string. A numeric argument is converted to its equivalent binary string form; if you want to avoid that you can use explicit type cast, like in this example: SELECT CONCAT(CAST(int_col AS CHAR), char_col)

    mysql> SELECT CONCAT('My', 'S', 'QL');
    -> 'MySQL'
    mysql> SELECT CONCAT('My', NULL, 'QL');
    -> NULL
    mysql> SELECT CONCAT(14.3);
    -> '14.3'

    CONCAT_WS(separator,str1,str2,...)

    CONCAT_WS() stands for CONCAT With Separator and is a special form of CONCAT(). The first argument is the separator for the rest of the arguments. The separator is added between the strings to be concatenated. The separator can be a string as can the rest of the arguments. If the separator is NULL, the result is NULL. The function skips any NULL values after the separator argument.

    mysql> SELECT CONCAT_WS(',','First name','Second name','Last Name');
    -> 'First name,Second name,Last Name'
    mysql> SELECT CONCAT_WS(',','First name',NULL,'Last Name');
    -> 'First name,Last Name'

    Before MySQL 4.0.14, CONCAT_WS() skips empty strings as well as NULL values.

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  6. #6
    Utente di HTML.it L'avatar di gianiaz
    Registrato dal
    May 2001
    Messaggi
    8,027
    echo "grazie a tutti e due";

  7. #7
    Utente di HTML.it
    Registrato dal
    Oct 2004
    Messaggi
    184
    Ciao a tutti,
    stò cercando di usare il CONCAT cosi come suggerito, ma in pratica non succede nulla, i dati non vengono scritti nel DB, può dipendere dal fatto ke il campo su cui devo scrivere è un campo longtext che all'inizio potrebbe essere vuoto?


    Grazie
    Stefano

  8. #8
    Utente di HTML.it
    Registrato dal
    Oct 2004
    Messaggi
    184
    ok ho risolto, in sostanza il campo non deve essere NULL altrimenti non fa la concat...



    Stefano

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.