Get started with PHP-Fusion

Start a New Thread

Users Participated

  • Craig
    Post made: 2
  • Wanabo
    Post made: 3
  • PolarFox
    Post made: 1

  1. PHP-Fusion Support Forums
  2. General Addon and Modification Support
  3. Code Snippet and functions

How to check if a thread_subject already exists in DB_THREADS

Post your code snippets here

5 Replies 1,807 Views Last Updated on 4 years ago

Wanabo


Senior Member

#1

Posted 4 years ago

I need to check if a thread_subject already exists in DB_THREADS

I thought this code would work but it does not work. Obviously the $title variable needs to be checked against existing thread_subjects.

[syntaxhighlighter brush=php,first-line=1,highlight=0,collapse=false,html-script=false]$uniqueCheck = dbcount("(forum_id)", DB_THREADS, "thread_subject='".$title."'");
if ($uniqueCheck != 0) { echo "no matching thread subject found";}
[/syntaxhighlighter]

The uniqueCheck was taken from forums.php

Who can help me out?
Edited by Wanabo on 10-12-2011 01:33
pHp-Fusion.Org, tutorials to enhance php-fusion.
pHp-Fusion.Asia & pHp-Fusion.Fr & pHp-Fusion.Cn are available for a localized support site. Send PB for info.

Posts: 435

Joined: 06/02/2006

Craig


Fusioneer

#2

Posted 4 years ago

Code Gist: Download source  
<?php
$subject ="The Thread Subject Here"; // Thread subject
$check = dbquery("SELECT thread_subject FROM ".DB_THREADS." WHERE thread_subject='".$subject."'");
if (dbrows($check) > 0) {
echo"True"; // If Result True
}else{
echo"False"; // If Result False
}
?>

Posts: 4526

Joined: 27/09/2005

Wanabo


Senior Member

#3

Posted 4 years ago

Thanks, but I just figured out an other solution. :)

[syntaxhighlighter brush=php,first-line=1,highlight=0,collapse=false,html-script=false]
$uniqueCheck = dbcount("(forum_id)", DB_THREADS, "thread_subject='".$title."'");
if ($uniqueCheck == 0) {
[/syntaxhighlighter]

It was this != versus == thing that got me on the wrong foot.
Edited by Wanabo on 10-12-2011 01:59
pHp-Fusion.Org, tutorials to enhance php-fusion.
pHp-Fusion.Asia & pHp-Fusion.Fr & pHp-Fusion.Cn are available for a localized support site. Send PB for info.

Posts: 435

Joined: 06/02/2006

Craig


Fusioneer

#4

Posts: 4526

Joined: 27/09/2005

PolarFox


Admin

#5

Posted 4 years ago

[syntaxhighlighter brush=php,first-line=1,highlight=0,collapse=false,html-script=false]$uniqueCheck = dbcount("(forum_id)", DB_THREADS, "thread_subject='".$title."'")?false:true;[/syntaxhighlighter]

Posts: 1641

Joined: 26/08/2008

Wanabo


Senior Member

#6

Posted 4 years ago

PolarFox wrote:

[syntaxhighlighter brush=php,first-line=1,highlight=0,collapse=false,html-script=false]$uniqueCheck = dbcount("(forum_id)", DB_THREADS, "thread_subject='".$title."'")?false:true;[/syntaxhighlighter]


Thanks Polarfox. I'm not so familiar with switches so to use the switch it would be something like this.

[syntaxhighlighter brush=php,first-line=1,highlight=0,collapse=false,html-script=false]if $uniqueCheck = FALSE { do my php stuff }[/syntaxhighlighter]

Hint for developers: if syntaxhighlighter (or other bbcode for code is used) disable smileys.
pHp-Fusion.Org, tutorials to enhance php-fusion.
pHp-Fusion.Asia & pHp-Fusion.Fr & pHp-Fusion.Cn are available for a localized support site. Send PB for info.

Posts: 435

Joined: 06/02/2006

Jump to Forum:
16 users are online
0 member and 16 guests