vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   SQL query to search and change prefixes (https://vborg.vbsupport.ru/showthread.php?t=299427)

Morrus 06-23-2013 11:31 AM

SQL query to search and change prefixes
 
I need to add large numbers of thread prefixes based on keywords in the thread titles. At the moment, I'm spending hours laboriously searching for keywords, opening threads, editing them, and saving them again- all one at a time. There are inline prefix change mods around, but they don't work on the search results pages.

Could anyone advise on the SQL query I'd need to run to do the following:

Change thread prefix to X for all threads in Forum Y whose title contain the string Z.

(e.g. change thread prefix to Apples for all threads in Food Forum whose titles contain the word "apple").

Thanks in advance for any help!

kh99 06-23-2013 01:27 PM

You need to use the prefix ids and not the label (you can see the ids in the prefix manager). But this should work:

Code:

UPDATE thread SET prefixid = 'x' WHERE forumid = Y AND title LIKE '%Z%'

Morrus 06-23-2013 01:39 PM

Thanks! Are those % symbols wildcards?

Lynne 06-23-2013 01:45 PM

Yes, % is a MySQL wildcard.

It is strongly suggested to test queries on a test database before doing so on the live database. Also make sure you do a database backup prior to running any queries on your live database.

Morrus 06-23-2013 01:58 PM

Yep, understood. Thanks!

As a further question - if I want a space in the search string (say "green apples") do I need to use a special character or just use the space as normal?

kh99 06-23-2013 02:23 PM

Spaces are ok because the string is in quotes. But some characters would need to be escaped. If you want to match a literal '%' or '_' (underscore matches any single char), or a single quote, you would need to put a backslash before them.

Morrus 06-23-2013 02:54 PM

Fantastic. Thanks for the help!


All times are GMT. The time now is 03:11 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01485 seconds
  • Memory Usage 1,715KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete