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???
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
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
$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
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.
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