简体   繁体   中英

Remove characters from SUBSTRING_INDEX

I'm unserialize the data below

a:7:{s:12:"existingname";s:0:"";s:12:"originalname";s:50:"165074-mort-de-l-historien-jean-pierre-vernant.jpg";s:3:"alt";s:0:"";s:5:"title";s:0:"";s:4:"desc";s:0:"";s:6:"delete";b:0;s:6:"remove";b:0;}

using this quote

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(value,';',4),':',-1) AS bookimage 
  FROM jksid_flexicontent_fields_item_relations 
 WHERE jksid_flexicontent_fields_item_relations.field_id = 17  
   AND jksid_flexicontent_fields_item_relations.ite m_id = 13153

the result I have is

"165074-mort-de-l-historien-jean-pierre-vernant.jpg"

How can I remove the " symbols ?

Try to use replace function.
For excample: REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(value,';',4),':',-1), '\\"', '')

SELECT REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(value,';',4),':',-1),'"','')  AS bookimage 
  FROM jksid_flexicontent_fields_item_relations 
 WHERE jksid_flexicontent_fields_item_relations.field_id = 17  
   AND jksid_flexicontent_fields_item_relations.ite m_id = 13153

I think I stack again

When I copy it on the quote I've got syntax error

<?php
// get book image
mysql_select_db($database_fsd, $fsd);
$query_wrtbkimg = "
SELECT REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(value,';',4),':',-1),'"','')  AS bookimage 
  FROM jksid_flexicontent_fields_item_relations 
 WHERE jksid_flexicontent_fields_item_relations.field_id = 17  
   AND jksid_flexicontent_fields_item_relations.ite m_id = 13153
";
$wrtbkimg = mysql_query($query_wrtbkimg, $fsd) or die(mysql_error());
$row_wrtbkimg = mysql_fetch_assoc($wrtbkimg);
$totalRows_wrtbkimg = mysql_num_rows($hwrtbkimg);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM