Hi I need away to do the following (NOTE MYSQL code done just need to know how to use case to run different mysql's
if the user types is stock:Telstra then it searches all of the database
but if they type in stock:asx.Telstra then it runs the case stock but then see that there is the asx. and runs that Mysql that is in that case.
Can you help
<?php
$parts = explode(":",$q);
switch($parts[0])
{
case "Stock":
case "stock":
//code
break;
}
?>

I am also having a small
I am also having a small issue with the following code, It works fine when searching 4 letters or more but I have many 3 letter codes in my DB and this code just does not like 3 letters
SELECT *, match(symbol) against('TLS') as symbol_score, match(company) against('TLS') as score FROM `tbl_stock_ids` WHERE MATCH (symbol) AGAINST ('TLS') OR MATCH (company) AGAINST ('TLS') Order BY symbol_score DESC, score DESCHello Russell, It looks like
Hello Russell,
It looks like you want to secondly explode $parts[1] on the "." character (after doing an strpos for efficiency) and then modify your SQL accordingly.... For example:
<?php$parts = explode(":",$q);
switch(strtolower($parts[0]))
{
case "stock":
if (strpos($parts[1],".")!==FALSE)
{
$parts2 = explode(".",$parts[1]);
// here, asx as per your example would be in $parts2[0] for use in SQL
}
else
{
// here, use $parts[1] as normal for use in SQL
}
break;
}
?>
Hope this helps!
Cheers,
David.
...secondly regarding your
...secondly regarding your SQL issue - that's happening because you are using a FULLTEXT index, but any words less than 4 characters are not indexed by the FULLTEXT index method.
In this case, instead of
match(company) against ('TLS')...use
company = 'TLS'That should do the trick!
Cheers,
David.
So I guess then how would i
So I guess then how would i do a score? like the match and against?
David how do i count the
David how do i count the number of letters in the $q ?
I want it so if they type 3 or less it does one thing and if more then 4 it runs the match script...
Hi Russell, Just use
Hi Russell,
Just use strlen(), for example:
if (strlen($q) < 4){
// do this
}
else
{
// do this
}