| FAQ |
| Kalender |
|
|
#1 | ||
|
|||
|
Medlem
|
Hej!
Jag vill kunna splitta en kolumn med en funktion som jag har här. Kod:
CREATE FUNCTION stringSplit( x VARCHAR(255), delim VARCHAR(12), pos INT) RETURNS VARCHAR(255) RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), delim, ''); Vi ansluter oss till databasen genom PHP och vi måste då splitta en kolumn därifrån. Såhär provade jag men det funkade inte. Kod:
$database->query("
CREATE FUNCTION stringSplit(
x VARCHAR(255),
delim VARCHAR(12),
pos INT)
RETURNS VARCHAR(255)
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos),
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), delim, '');
SELECT stringSplit(xp.data, ' ', 1) AS key FROM ws_1o5_hns_xp xp JOIN table2 ON table2.id = key WHERE xp.certain_id = 2
");
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key FROM ws_1o5_hns_xp xp' at line 1 |
||
|
|
Svara med citat
|
|
|