Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    Help con una espressione regolare

    Partendo da una stringa del tipo:

    WHERE `Campo1`!=Valore1 AND
    `Campo2`!=Valore2 OR
    (`Campo3`!=Valore3 AND
    `Campo4`!=Valore4)

    Vorrei sostituire tutte le occorrenze di
    `CampoX`!=Valore X
    con
    (`CampoX`!=Valore X OR `CampoX IS NULL)

    Come si fa???
    All work and no play makes EricFlat a dull boy

  2. #2
    Il tutto perche' a priori non so se un certo campo contiene un valore oppure e' NULL.

    Pero' devo controllare che il campo non sia uguale ad un certo valore e ovviamente se e' NULL per me va bene lo stesso, ma per MySQL no...

    Come posso aggirare sto problema???

    All work and no play makes EricFlat a dull boy

  3. #3
    $filter = preg_replace("%(?:\(|\s)(\S+)!=(\S+)(?:\)|\s)%", "($1!=$2 OR $1 IS NULL)", $filter);

    Non funziona

    HELP!!!!
    All work and no play makes EricFlat a dull boy

  4. #4
    Tutto dipende dal tipo di ValoreX. Cmq cercando di essere generici prova cosė:

    codice:
    $myQuery = '....';
    $type='[^\s\)]+';
    $myQuery = preg_replace("/(`[^`]+`)!=$type/",'($0 OR $1 IS NULL)',$myQuery);
    dA .. foto di viaggio
    L'esperienza č il tipo di insegnante pių difficile.
    Prima ti fa l'esame, e poi ti spiega la lezione.

  5. #5
    Pare che ci sono riuscito facendo cosi':

    Codice PHP:
    $regexp  "%"// Start of the regexp
    $regexp .= "(?:\s|\()?"// A space or an opening bracket
    $regexp .= "(\S+)"// Capture the field name to $1
    $regexp .= "!="// The != operator
    $regexp .= "(\S+)"// Capture the value to $2
    $regexp .= "(?:\s|\))?"// A space or a closing bracket
    $regexp .= "%"// End of the regexp

    $filter preg_replace($regexp"($1!=$2 OR $1 IS NULL) "$filter); 
    All work and no play makes EricFlat a dull boy

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 © 2024 vBulletin Solutions, Inc. All rights reserved.