久久久久av_欧美日韩一区二区在线_国产精品三区四区_日韩中字在线

Discuz! 官方交流社區

標題: 分類信息字段中的選擇和多選的數據庫表,123替換 [打印本頁]

作者: roc29a    時間: 2023-9-26 14:23
標題: 分類信息字段中的選擇和多選的數據庫表,123替換
pre_forum_typeoption數據庫表在選擇或多選時有1=xx2=yy3=zz等等。pre_forum_typeoptionvar表及pre_forum_optionvalue1用123代表式,怎么能讓這兩個表篩選并輸出變量,1替換為xx,2替換為yy,3替換為zz等等

作者: 科站網    時間: 2023-9-26 14:32
你看到是123,但實際中間有一個制表符,應該是
  1. 1        2
復制代碼

作者: roc29a    時間: 2023-9-26 14:38
科站網 發表于 2023-9-26 14:32
你看到是123,但實際中間有一個制表符,應該是

嗯,看起來像個空格,能去掉,整體我就搞不下來了。
作者: 科站網    時間: 2023-9-26 14:45
mysql update replace下
作者: 科站網    時間: 2023-9-26 14:45
再不行寫個腳本跑一下
作者: roc29a    時間: 2023-9-26 14:58
科站網 發表于 2023-9-26 14:45
mysql update replace下

這個不行啊,不想改變數據庫字段值
作者: roc29a    時間: 2023-9-26 15:00
科站網 發表于 2023-9-26 14:45
再不行寫個腳本跑一下

已經查資料,查百度,查百度AI折磨四五天了,我是初學者還是沒搞定
作者: 酷畫創意    時間: 2023-9-26 17:52
不太清楚你的具體訴求,但如果是要在帖子內容頁特定顯示分類字段的信息,可以直接編寫自定義分類信息的帖子內容頁模板,想怎么調用就怎么調用。如果是要在其他地方篩選分類信息字段展示,看能不能在后端獲取到帖子的分類信息字段變量寫一個邏輯判斷來輸出,沒必要動數據庫字段信息
作者: roc29a    時間: 2023-9-27 08:29
酷畫創意 發表于 2023-9-26 17:52
不太清楚你的具體訴求,但如果是要在帖子內容頁特定顯示分類字段的信息,可以直接編寫自定義分類信息的帖子 ...

帖子內容頁的內容能調到門戶文章內嗎?想把帖子的分類信息模板和內容調到文章里去。我這是在走數據庫表去實現
作者: 科站網    時間: 2023-9-27 08:37
roc29a 發表于 2023-9-27 08:29
帖子內容頁的內容能調到門戶文章內嗎?想把帖子的分類信息模板和內容調到文章里去。我這是在走數據庫表去 ...

直接寫一個插件不就完事了
作者: roc29a    時間: 2023-9-27 08:53
$tid=任意帖子ID;
pre_forum_typeoptionvar表:$typeoption = DB::fetch_all("SELECT rules FROM %t WHERE optionid > %d", array('forum_typeoption', 6));
pre_forum_typeoptionvar表:$typeoptionvar = DB::fetch_all("SELECT value FROM %t WHERE tid = %d", array('forum_typeoptionvar', $tid));
pre_forum_optionvalue1表:$optionvalue1= DB::fetch_first("SELECT * FROM %t WHERE tid = %d", array('forum_optionvalue1', $tid));
這時$typeoption的選擇和多選的字段對應的元素中會出現1=xx2=yy3=zz還有其他不知道什么碼包圍。$typeoptionvar和$optionvalue1的選擇和多選的元素中會有某個選項1或2或3或23或13或23或123等等。其實123就是代表值,怎么能讓這兩個變量$typeoptionvar和$optionvalue1,1替換為xx,2替換為yy,3替換為zz等等



作者: roc29a    時間: 2023-9-27 08:55
roc29a 發表于 2023-9-27 08:53
$tid=任意帖子ID;
pre_forum_typeoptionvar表:$typeoption = DB::fetch_all("SELECT rules FROM %t WHERE  ...

這是一個PHP處理數組的問題
作者: roc29a    時間: 2023-9-27 09:08
科站網 發表于 2023-9-27 08:37
直接寫一個插件不就完事了

正是在寫插件代碼,可是不大會
作者: 科站網    時間: 2023-9-27 09:15
roc29a 發表于 2023-9-27 09:08
正是在寫插件代碼,可是不大會

定制或者開發文檔:https://www.discuzlab.com/x-docs/develop/dev.html

作者: 酷畫創意    時間: 2023-9-27 09:19
roc29a 發表于 2023-9-27 08:29
帖子內容頁的內容能調到門戶文章內嗎?想把帖子的分類信息模板和內容調到文章里去。我這是在走數據庫表去 ...

打擾,再見!
作者: roc29a    時間: 2023-9-27 09:36
酷畫創意 發表于 2023-9-27 09:19
打擾,再見!

想把發帖投稿到文章中去,有這個插件,但不能滿足分類信息投稿到文章,是在解決這個問題。并不是DIY調用帖子。感謝參與我的問題,剛才說的急,冒犯了。
作者: roc29a    時間: 2023-9-27 09:39
科站網 發表于 2023-9-27 09:15
定制或者開發文檔:https://www.discuzlab.com/x-docs/develop/dev.html

只需處理數組問題就行了,需要PHP知識處理,我匱乏這方面知識。感謝大力支持
作者: roc29a    時間: 2023-9-27 09:46
rules部分:[rules]={1=xx2=yy3=zz}
value部分:[value]={123}
某字段值:[字段]={123}
需求結果:
value部分:[value]={xx,yy,zz}
某字段值:[字段}={xx,yy,zz}
作者: roc29a    時間: 2023-10-6 09:34
<!-- forum_typeoption表中所有1 = xx 2 = yy 3 = zz更改為 [rules]xx yy zz -->
$typeoption = DB::fetch_all("SELECT optionid,rules FROM %t WHERE optionid > %d", array('forum_typeoption', 6));
$typeoptionvar = DB::fetch_all("SELECT optionid,value FROM %t WHERE tid = %d", array('forum_typeoptionvar', $tid));
//取出含數字字符串中最大的數字
function extractMaxNumber($str) {
  $maxNumber = '';
  $isNumber = false;
  for ($i = 0; $i < strlen($str); $i++) {
    if (is_numeric($str[$i])) {
      if (!$isNumber) {
        $maxNumber = $str[$i];
        $isNumber = true;
      } else {
        $maxNumber .= $str[$i];
      }
    } else {
      $isNumber = false;
    }
  }
  return (int) $maxNumber;
}
//$typeoption的[rules],$choices分割成數組
foreach ($typeoption as $keys => $types) {
  if (strpos($types[rules], 'choices') !== false) {//$typeoption找出選擇和多選的rules
    $choices[$keys][rules]=$types[rules];
    $optionids[$keys]=$types[optionid];
    $optionids=array_values($optionids);
    $choices[$keys][rules]=strstr($choices[$keys][rules],'1 = ');
    $choices[$keys][rules]=strstr($choices[$keys][rules],'"',true);//把數組截取
      for($i=1;$i<=extractMaxNumber($choices[$keys][rules]);$i++){
        $choices[$keys][rules]=str_replace("$i = ", ",$i=", $choices[$keys][rules]);
      }
    $choices[$keys][rules]=substr($choices[$keys][rules],1);//去除第一個字符
    $choices[$keys][rules]=explode(",",$choices[$keys][rules]);//字符串分割成數組
    $typeoption[$keys][rules]=$choices[$keys][rules];
  }
}

//$typeoptionvar,$optionids數組里的$choice分割成數組并替換
foreach ($typeoptionvar as $key => $type){
  if (in_array($type[optionid], $optionids)){
    $choice[$key][rules]=$type[value];
      for($i=1;$i<=extractMaxNumber($choice[$key][rules]);$i++){
        $choice[$key][rules]=preg_replace('/\s+/','', $choice[$key][rules]);
      }
    $choice[$key][rules]=str_split($choice[$key][rules]);
    //把$choice最底層數組含數字元素替換成對應的$choices含有數字的元素并去除數字和=
    foreach($choice[$key][rules] as $tion => $rule){
      foreach($choices[$key][rules] as $tions => $rules){
        if (strpos($rules, "$rule") !== false) {
          $choice[$key][rules][$tion]=$choices[$key][rules][$choice[$key][rules][$tion]-1];
        }
      }
      for($i=1;$i<=extractMaxNumber($choice[$key][rules][$tion]);$i++){
        $choice[$key][rules][$tion]=str_replace("$i=", " ", $choice[$key][rules][$tion]);
      }
      
      
    }
    $choice[$key][rules]=implode(" ", $choice[$key][rules]);
    $typeoptionvar[$key][value]=$choice[$key][rules];
  }
}
作者: roc29a    時間: 2023-10-6 09:36
roc29a 發表于 2023-10-6 09:34
$typeoption = DB::fetch_all("SELECT optionid,rules FROM %t WHERE optionid > %d", array('forum_typeo ...
  1. <!-- forum_typeoption表中所有1 = xx 2 = yy 3 = zz更改為 [rules]xx yy zz -->
  2. $typeoption = DB::fetch_all("SELECT optionid,rules FROM %t WHERE optionid > %d", array('forum_typeoption', 6));
  3. $typeoptionvar = DB::fetch_all("SELECT optionid,value FROM %t WHERE tid = %d", array('forum_typeoptionvar', $tid));
  4. //取出含數字字符串中最大的數字
  5. function extractMaxNumber($str) {
  6.   $maxNumber = '';
  7.   $isNumber = false;
  8.   for ($i = 0; $i < strlen($str); $i++) {
  9.     if (is_numeric($str[$i])) {
  10.       if (!$isNumber) {
  11.         $maxNumber = $str[$i];
  12.         $isNumber = true;
  13.       } else {
  14.         $maxNumber .= $str[$i];
  15.       }
  16.     } else {
  17.       $isNumber = false;
  18.     }
  19.   }
  20.   return (int) $maxNumber;
  21. }
  22. //$typeoption的[rules],$choices分割成數組
  23. foreach ($typeoption as $keys => $types) {
  24.   if (strpos($types[rules], 'choices') !== false) {//$typeoption找出選擇和多選的rules
  25.     $choices[$keys][rules]=$types[rules];
  26.     $optionids[$keys]=$types[optionid];
  27.     $optionids=array_values($optionids);
  28.     $choices[$keys][rules]=strstr($choices[$keys][rules],'1 = ');
  29.     $choices[$keys][rules]=strstr($choices[$keys][rules],'"',true);//把數組截取
  30.       for($i=1;$i<=extractMaxNumber($choices[$keys][rules]);$i++){
  31.         $choices[$keys][rules]=str_replace("$i = ", ",$i=", $choices[$keys][rules]);
  32.       }
  33.     $choices[$keys][rules]=substr($choices[$keys][rules],1);//去除第一個字符
  34.     $choices[$keys][rules]=explode(",",$choices[$keys][rules]);//字符串分割成數組
  35.     $typeoption[$keys][rules]=$choices[$keys][rules];
  36.   }
  37. }

  38. //$typeoptionvar,$optionids數組里的$choice分割成數組并替換
  39. foreach ($typeoptionvar as $key => $type){
  40.   if (in_array($type[optionid], $optionids)){
  41.     $choice[$key][rules]=$type[value];
  42.       for($i=1;$i<=extractMaxNumber($choice[$key][rules]);$i++){
  43.         $choice[$key][rules]=preg_replace('/\s+/','', $choice[$key][rules]);
  44.       }
  45.     $choice[$key][rules]=str_split($choice[$key][rules]);
  46.     //把$choice最底層數組含數字元素替換成對應的$choices含有數字的元素并去除數字和=
  47.     foreach($choice[$key][rules] as $tion => $rule){
  48.       foreach($choices[$key][rules] as $tions => $rules){
  49.         if (strpos($rules, "$rule") !== false) {
  50.           $choice[$key][rules][$tion]=$choices[$key][rules][$choice[$key][rules][$tion]-1];
  51.         }
  52.       }
  53.       for($i=1;$i<=extractMaxNumber($choice[$key][rules][$tion]);$i++){
  54.         $choice[$key][rules][$tion]=str_replace("$i=", " ", $choice[$key][rules][$tion]);
  55.       }
  56.       
  57.       
  58.     }
  59.     $choice[$key][rules]=implode(" ", $choice[$key][rules]);
  60.     $typeoptionvar[$key][value]=$choice[$key][rules];
  61.   }
  62. }
復制代碼

作者: roc29a    時間: 2023-10-6 09:38
  1. <!-- forum_typeoption表中所有1 = xx 2 = yy 3 = zz更改為 [rules]xx yy zz -->
  2. $typeoption = DB::fetch_all("SELECT optionid,rules FROM %t WHERE optionid > %d", array('forum_typeoption', 6));
  3. $typeoptionvar = DB::fetch_all("SELECT optionid,value FROM %t WHERE tid = %d", array('forum_typeoptionvar', $tid));
  4. //取出含數字字符串中最大的數字
  5. function extractMaxNumber($str) {
  6.   $maxNumber = '';
  7.   $isNumber = false;
  8.   for ($i = 0; $i < strlen($str); $i++) {
  9.     if (is_numeric($str[$i])) {
  10.       if (!$isNumber) {
  11.         $maxNumber = $str[$i];
  12.         $isNumber = true;
  13.       } else {
  14.         $maxNumber .= $str[$i];
  15.       }
  16.     } else {
  17.       $isNumber = false;
  18.     }
  19.   }
  20.   return (int) $maxNumber;
  21. }
  22. //$typeoption的[rules],$choices分割成數組
  23. foreach ($typeoption as $keys => $types) {
  24.   if (strpos($types[rules], 'choices') !== false) {//$typeoption找出選擇和多選的rules
  25.     $choices[$keys][rules]=$types[rules];
  26.     $optionids[$keys]=$types[optionid];
  27.     $optionids=array_values($optionids);
  28.     $choices[$keys][rules]=strstr($choices[$keys][rules],'1 = ');
  29.     $choices[$keys][rules]=strstr($choices[$keys][rules],'"',true);//把數組截取
  30.       for($i=1;$i<=extractMaxNumber($choices[$keys][rules]);$i++){
  31.         $choices[$keys][rules]=str_replace("$i = ", ",$i=", $choices[$keys][rules]);
  32.       }
  33.     $choices[$keys][rules]=substr($choices[$keys][rules],1);//去除第一個字符
  34.     $choices[$keys][rules]=explode(",",$choices[$keys][rules]);//字符串分割成數組
  35.     $typeoption[$keys][rules]=$choices[$keys][rules];
  36.   }
  37. }

  38. //$typeoptionvar,$optionids數組里的$choice分割成數組并替換
  39. foreach ($typeoptionvar as $key => $type){
  40.   if (in_array($type[optionid], $optionids)){
  41.     $choice[$key][rules]=$type[value];
  42.       for($i=1;$i<=extractMaxNumber($choice[$key][rules]);$i++){
  43.         $choice[$key][rules]=preg_replace('/\s+/','', $choice[$key][rules]);
  44.       }
  45.     $choice[$key][rules]=str_split($choice[$key][rules]);
  46.     //把$choice最底層數組含數字元素替換成對應的$choices含有數字的元素并去除數字和=
  47.     foreach($choice[$key][rules] as $tion => $rule){
  48.       foreach($choices[$key][rules] as $tions => $rules){
  49.         if (strpos($rules, "$rule") !== false) {
  50.           $choice[$key][rules][$tion]=$choices[$key][rules][$choice[$key][rules][$tion]-1];
  51.         }
  52.       }
  53.       for($i=1;$i<=extractMaxNumber($choice[$key][rules][$tion]);$i++){
  54.         $choice[$key][rules][$tion]=str_replace("$i=", " ", $choice[$key][rules][$tion]);
  55.       }
  56.       
  57.       
  58.     }
  59.     $choice[$key][rules]=implode(" ", $choice[$key][rules]);
  60.     $typeoptionvar[$key][value]=$choice[$key][rules];
  61.   }
  62. }
復制代碼



作者: roc29a    時間: 2023-10-6 10:33
改進了一下,并把圖片的雜亂碼去掉
  1. //取出含數字字符串中最大的數字
  2. function extractMaxNumber($str) {
  3.   $maxNumber = '';
  4.   $isNumber = false;
  5.   for ($i = 0; $i < strlen($str); $i++) {
  6.     if (is_numeric($str[$i])) {
  7.       if (!$isNumber) {
  8.         $maxNumber = $str[$i];
  9.         $isNumber = true;
  10.       } else {
  11.         $maxNumber .= $str[$i];
  12.       }
  13.     } else {
  14.       $isNumber = false;
  15.     }
  16.   }
  17.   return (int) $maxNumber;
  18. }
  19. //$typeoption的[rules],$choices分割成數組
  20. foreach ($typeoption as $keys => $types) {
  21.   if (strpos($types[rules], 'choices') !== false) {//$typeoption找出選擇和多選的rules
  22.     $choices[$keys][rules]=$types[rules];
  23.     $optionids[$keys]=$types[optionid];
  24.     $optionids=array_values($optionids);
  25.     $choices[$keys][rules]=strstr($choices[$keys][rules],'1 = ');
  26.     $choices[$keys][rules]=strstr($choices[$keys][rules],'"',true);//把數組截取
  27.       for($i=1;$i<=extractMaxNumber($choices[$keys][rules]);$i++){
  28.         $choices[$keys][rules]=str_replace("$i = ", ",$i=", $choices[$keys][rules]);
  29.       }
  30.     $choices[$keys][rules]=substr($choices[$keys][rules],1);//去除第一個字符
  31.     $choices[$keys][rules]=explode(",",$choices[$keys][rules]);//字符串分割成數組
  32.     $typeoption[$keys][rules]=$choices[$keys][rules];
  33.   }
  34. }

  35. //$typeoptionvar,$optionids數組里的$choice分割成數組并替換
  36. foreach ($typeoptionvar as $key => $type){
  37.   if (in_array($type[optionid], $optionids)){
  38.     $choice[$key][value]=$type[value];
  39.       for($i=1;$i<=extractMaxNumber($choice[$key][value]);$i++){
  40.         $choice[$key][value]=preg_replace('/\s+/','', $choice[$key][value]);
  41.       }
  42.     $choice[$key][value]=str_split($choice[$key][value]);
  43.     //把$choice最底層數組含數字元素替換成對應的$choices含有數字的元素并去除數字和=
  44.     foreach($choice[$key][value] as $tion => $rule){
  45.       foreach($choices[$key][rules] as $tions => $rules){
  46.         if (strpos($rules, "$rule") !== false) {
  47.           $choice[$key][value][$tion]=$choices[$key][rules][$choice[$key][value][$tion]-1];
  48.         }
  49.       }
  50.       for($i=1;$i<=extractMaxNumber($choice[$key][value][$tion]);$i++){
  51.         $choice[$key][value][$tion]=str_replace("$i=", " ", $choice[$key][value][$tion]);
  52.       }   
  53.     }
  54.     $choice[$key][value]=implode(" ", $choice[$key][value]);
  55.     $typeoptionvar[$key][value]=$choice[$key][value];
  56.   }
  57. }

  58. foreach ($typeoptionvar as $key => $type) {
  59.     if (strpos($type[value], 'data') !== false) {
  60.         $image[$key][value]=strstr($typeoptionvar[$key][value],'data');
  61.         $image[$key][value]=str_replace('";}','',$image[$key][value]);
  62.         $typeoptionvar[$key][value]=$image[$key][value];
  63.     }
  64. }
復制代碼





歡迎光臨 Discuz! 官方交流社區 (http://www.9999xn.com/) Powered by Discuz! W1.0