vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Comparing post titles with a variable (https://vborg.vbsupport.ru/showthread.php?t=73744)

alqadir 01-04-2005 05:29 AM

Comparing post titles with a variable
 
Hello all,
I was wondering if someone out there can help me out with some sql code. I am wanting to create a query that will search all the posts in the post table and compare the titles to a variable (say $formtitle). If it finds a match it will return the threadid of the matching title; thier can only be one matching title in the post so the limit should be one.

I have this so far but it is not working
Code:

$formtitle= "$answer1 $answer2)
$prevpost = $DB_site->query_first("SELECT * FROM post WHERE post.title='$formtitle' LIMIT 1");

I was wondering would I have to use the string compare command for this to work

rake 01-04-2005 08:32 AM

do you want the title to be EXACTLY the string you are searching for or not?

also:

$formtitle= "$answer1 $answer2)

should be:

$formtitle= "$answer1 $answer2";

alqadir 01-04-2005 09:01 AM

Yes I would like the title to match character for character.

opps. the $forumtitle should read the way you corrected it, I guess I was typing too fast. ;) thanks

rake 01-04-2005 09:13 AM

hrmm.... try this:

SELECT * FROM post WHERE post.title LIKE '$formtitle' LIMIT 1

Dean C 01-04-2005 11:14 AM

Use LIKE '%$formtitle%' if you want to match the pattern of that string in any occurence of any other string. E.g. Dan would match Danni :)

alqadir 01-10-2005 04:42 AM

both solutions did not work :( any other suggestions guys

cinq 01-10-2005 05:27 AM

Odd, previous solutions provided should work.

ie.
PHP Code:

$prevpost $DB_site->query("SELECT threadid FROM post WHERE title LIKE '%$formtitle%' LIMIT 1");
if(
$result=$DB_site->fetch_array($prevpost))
{
 
$output $result['threadid'];


With $formtitle being the variable you want to compare the post table with to find a post with similar title.

$output should return the result ( threadid ) if there is such a match.


All times are GMT. The time now is 10:24 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.01055 seconds
  • Memory Usage 1,722KB
  • 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)bbcode_php_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