0

所以我在这里得到了我的“小”代码:

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

//Verbindung
$connection = mysqli_connect('localhost', 'user', 'pw', 'db');

// search stuff
// Treuhandbetrag case 1
$suchstringanfang_treuhand1 = 'treuhand_betrag\"';
$suchstringende_treuhand1 = '\";';

// Treuhandbetrag case 2
$suchstringanfang_treuhand2 = 'treuhand_price\"';
$suchstringende_treuhand2 = '\";';

//queries
//Treuhandabfrage case 1
$query_treuhand1 = "SELECT SUBSTRING(LEFT(configuration, LOCATE('$suchstringende_treuhand1', configuration) +0), LOCATE('$suchstringanfang_treuhand1', configuration) +0, 100)
FROM tl_iso_product_collection_item
WHERE LOCATE('$suchstringende_treuhand1', configuration) > 0
AND LOCATE('$suchstringanfang_treuhand1', configuration) > 0 ORDER BY id DESC LIMIT 1";

//Treuhandabfrage case 2
$query_treuhand2 = "SELECT SUBSTRING(LEFT(configuration, LOCATE('$suchstringende_treuhand2', configuration) +0), LOCATE('$suchstringanfang_treuhand2', configuration) +0, 100)
FROM tl_iso_product_collection_item
WHERE LOCATE('$suchstringende_treuhand2', configuration) > 0
AND LOCATE('$suchstringanfang_treuhand2', configuration) > 0 ORDER BY id DESC LIMIT 1";

//results
// Treuhandbetrag
$result_treuhand1 = mysqli_query($connection, $query_treuhand1);
$result_treuhand2 = mysqli_query($connection, $query_treuhand2);

//Display results
if($result_treuhand2 === FALSE) { 
    echo mysqli_error($connection);
} else
    while($row = mysqli_fetch_array($result_treuhand2)){
print_r($row[0]);
}

//Close connection
mysqli_close($connection); 
?>

我基本上想做的是找到一个字符串

treuhand_betrag

和下一个发生

";

这是因为商店将所有属性数据存储在数据库的一个文本字段中。我知道这是一个紧急解决方案,但我迫切需要一些暂停。到目前为止,我的代码不会给我任何结果。如果我替换“;通过一些独特的东西,比如在现场只出现一次的‘treuhand_price’,我确实得到了想要的结果。

TEXT 字段的外观:如果有人提供所有信息,您可以期望该字段包含以下内容,例如:

a:14:{s:6:"roller";s:1:"9";s:16:"treuhand_abfrage";s:2:"37";s:15:"treuhand_betrag";s:4:"2000";s:13:"treuhand_price";s:2:"35";s:11:"abhol_firma";s:18:"NichtdieselbeFirma";s:13:"abhol_vorname";s:14:"AndererVorname";s:14:"abhol_nachname";s:15:"AndererNachname";s:12:"abhol_str_nr";s:15:"AndereStraße 7";s:9:"abhol_plz";s:6:"456465";s:9:"abhol_ort";s:12:"Dschingistan";s:10:"abhol_land";s:3:"Bla";s:13:"abhol_telefon";s:6:"564654";s:11:"abhol_email";s:10:"d.web@d.de";s:11:"bemerkungen";s:5:"aeawe";}

如果有人不在乎,也没有透露太多信息:

a:8:{s:6:"roller";s:1:"9";s:16:"treuhand_abfrage";s:2:"36";s:13:"treuhand_price";s:2:"35";s:13:"abhol_vorname";s:5:"Deniz";s:14:"abhol_nachname";s:5:"Cetin";s:12:"abhol_str_nr";s:10:"straße 38";s:9:"abhol_plz";s:5:"90461";s:9:"abhol_ort";s:9:"Nürnberg";}

我会很高兴得到一些帮助或提示!提前致谢!

4

1 回答 1

0

这是你想要的吗。它有点棘手。所以我反转字符串(和搜索字符串)以使用 SUBSTR_INDEX 从中获取其余部分。我已将您的字段名更改为此示例中的字符串

SELECT
  SUBSTRING_INDEX(REVERSE(
   SUBSTRING_INDEX(SUBSTRING_INDEX(
   REVERSE('a:14:{s:6:"roller";s:1:"9";s:16:"treuhand_abfrage";s:2:"37";s:15:"treuhand_betrag";s:4:"2000";s:13:"treuhand_price";s:2:"35";s:11:"abhol_firma";s:18:"NichtdieselbeFirma";s:13:"abhol_vorname";s:14:"AndererVorname";s:14:"abhol_nachname";s:15:"AndererNachname";s:12:"abhol_str_nr";s:15:"AndereStraße 7";s:9:"abhol_plz";s:6:"456465";s:9:"abhol_ort";s:12:"Dschingistan";s:10:"abhol_land";s:3:"Bla";s:13:"abhol_telefon";s:6:"564654";s:11:"abhol_email";s:10:"d.web@d.de";s:11:"bemerkungen";s:5:"aeawe";}')
    ,'garteb_dnahuert'
    ,1),';"',-2)),'"',-1);

结果

2000

如果您搜索的是什么,请告诉我

我从我的答案复制到一个 mysql 客户端:

MariaDB [(none)]> SELECT
    ->   SUBSTRING_INDEX(REVERSE(
    ->    SUBSTRING_INDEX(SUBSTRING_INDEX(
    ->    REVERSE('a:14:{s:6:"roller";s:1:"9";s:16:"treuhand_abfrage";s:2:"37";s:15:"treuhand_betrag";s:4:"2000";s:13:"treuhand_price";s:2:"35";s:11:"abhol_firma";s:18:"NichtdieselbeFirma";s:13:"abhol_vorname";s:14:"AndererVorname";s:14:"abhol_nachname";s:15:"AndererNachname";s:12:"abhol_str_nr";s:15:"AndereStraße 7";s:9:"abhol_plz";s:6:"456465";s:9:"abhol_ort";s:12:"Dschingistan";s:10:"abhol_land";s:3:"Bla";s:13:"abhol_telefon";s:6:"564654";s:11:"abhol_email";s:10:"d.web@d.de";s:11:"bemerkungen";s:5:"aeawe";}')
    ->     ,'garteb_dnahuert'
    ->     ,1),';"',-2)),'"',-1);
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| SUBSTRING_INDEX(REVERSE(
   SUBSTRING_INDEX(SUBSTRING_INDEX(
   REVERSE('a:14:{s:6:"roller";s:1:"9";s:16:"treuhand_abfrage";s:2:"37";s:15:"treuhand_betrag";s:4:"2000";s:13:"treuhand_price";s:2:"35";s:11:"abhol_firma";s:18:"NichtdieselbeFirma";s:13:"abhol_v |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 2000                                                                                                                                                                                                                                                             |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]>
于 2016-02-05T13:03:09.970 回答