Unstoppable Domains โ€” Expired Auctions

Fulltext mysql query not working! Help!

SpaceshipSpaceship
Watch

PoorDoggie

Soon to be RICHdoggie!VIP Member
Impact
18
PHP:
<?php

    include('config.php');

    if( isset($_POST['q']) ){

        // if a form was submitted
        $sql = "SELECT * FROM ".$config['table']." WHERE MATCH (".$config['name'].",".$config['type'].",".$config['glass'].") AGAINST ('".$_POST['q']."')";
        
        $result = mysql_query($sql);
        
        if( !$result ){

            echo "could not query database: ".die(mysql_error());

        }
        
        $b = mysql_num_rows($result);
        
        echo $b;
        
        while( $a = mysql_fetch_array($result) ){

            echo "Name: ";
            echo $a['name'];

        }
    
    }
    else{

        // if a form was NOT submitted
        // display the form
        
        ?>
        
        <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
            <input name="q" id="q" /><input type="submit" id="submit" />
        </form>
        
        <?php

    }

?>

That is my script, and it dosen't work. I put [into the input named "q"] the exact value of one of the values, but it still outputs "0" to $b. Help!

Thanks
Tom
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
can you post a built query

just echo $sql

also have you created the indexes?
 
0
•••
adam_uk said:
can you post a built query

just echo $sql

also have you created the indexes?
SELECT * FROM drinks WHERE MATCH (drink_name,drink_type,drink_glass) AGAINST ('search_term')

what do you mean created the indexes? I did "... FULLTEXT (drink_name,drink_type,drink_glass)..." in the "create table" mysql coding.
 
0
•••
PoorDoggie said:
SELECT * FROM drinks WHERE MATCH (drink_name,drink_type,drink_glass) AGAINST ('search_term')

what do you mean created the indexes? I did "... FULLTEXT (drink_name,drink_type,drink_glass)..." in the "create table" mysql coding.

when using fulltext searching you need to make indexes of your data, this is where the searches are.

ie did you exectue a sql query like this:

CREATE FULLTEXT INDEX full_index ON mytable(
mytable_title ,
mytable_caption ,
mytable_full_body
);

if you didnt this is why your fulltext searches are not operating

it can get quite complex if your searching differenent columns each time

http://www.phpfreaks.com/tutorials/129/0.php
 
0
•••
adam_uk said:
when using fulltext searching you need to make indexes of your data, this is where the searches are.

ie did you exectue a sql query like this:



if you didnt this is why your fulltext searches are not operating

it can get quite complex if your searching differenent columns each time

http://www.phpfreaks.com/tutorials/129/0.php
what do I put where you have "mytable, mytable_title, mytable_caption & mytable_full_body"???
 
0
•••
you need to edit that query to match your table layout and the columns you want to create indexes for.

once you have the query built you need to execute it. via phpmyadmin. or via command on ssh.

if you read the article above it will explain it better than i can.
 
0
•••
thanks :)
 
0
•••
nope, still not working. Do you think it could be anything to do with my server? (either web server or mysql server?)
 
0
•••
Try it like this,

PHP:
        // if a form was submitted

$q = addslashes($_POST['q']); 

$sql = "SELECT * FROM ".$config['table']." WHERE ".$config['name']." like '%".$q."%' or ".$config['type']." like '%".$q."%' or ".$config['glass']." like '%".$q."%'";
 
0
•••
-RJ- said:
Try it like this,

PHP:
        // if a form was submitted

$q = addslashes($_POST['q']); 

$sql = "SELECT * FROM ".$config['table']." WHERE ".$config['name']." like '%".$q."%' or ".$config['type']." like '%".$q."%' or ".$config['glass']." like '%".$q."%'";
great! works... thanks! :)
 
0
•••
while that will work its not actually full text searching. and things like boolean searches wont work.
 
0
•••
adam_uk said:
while that will work its not actually full text searching. and things like boolean searches wont work.
you mean like: "drink +name" and "'drink name'" and stuff? I don't think that matters, it wasn't how I was gonna do it anyway! lol

Thanks all! :)
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
NameMaxi - Your Domain Has Buyers
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back