Page 1 of 1

KillaFonts Searching Function

Posted: Fri Nov 05, 2004 11:18 pm
by ner0
[b]Ok, heres my problem in brief:

I\'ve created a font viewer (beta) for KillaFonts.com, which works fine (not so much aesthetically) and the structure for this script is sound, however, I\'ve created a similar copy of this script, yet this version must implement a searching function, which will narrow down the results returned based on submitted criteria.

to start, I\'ll give you an example of my code so far:

[url=\"http://ner0.homelinux.com/dev/nero_php_problem.phps\"]Search Function Source [05/11/04][/url]

First of all, the initial few comments blocks can be ignored, I\'ve created and deleted loads of code between those comments that they\'ve become useless /blum.gif\' class=\'bbc_emoticon\' alt=\':P\' />

now, heres what I\'ve tried so far:

[quote]$query = mysql_query(\"SELECT * FROM fonts REGEXP \" . $preg . \" ORDER BY fname ASC LIMIT \" . $perpage);[/quote]
for the query with no offset, and
[quote]$query = mysql_query(\"SELECT * FROM fonts REGEXP \" . $preg . \" ORDER BY fname ASC LIMIT \" . $bottom . \",\" . $perpage);[/quote]
for the query with an offset specified.

now this -would- theoretically work fine if i\'d put in a feasible query, BUT I can\'t do this as I need to select the fonts ID field (primary key, therefore unique) hence me putting a wildcard for the SELECT FROM statement, thus causing the regexp to basically do nothing as mysql isn\'t comparing it to anything...

why can\'t I put ID in the select from statement? i\'ve asked that to myself too, but then REGEXP would be trying to match a regular expression (the search criteria) to the fonts ID (a short integer), obviously this will not work either.

I\'ve EVEN tried scrapping any regexp term in the query, and filtering the results later, example:

[quote]$a = \'0\';
 
  $preg = \"/.*\" . $search . \".*/i\";
  while ($fonts=mysql_fetch_array($query))
  {
  $fonts_id = $fonts[\"id\"];
  $tempquery = mysql_query(\"SELECT \" . $type . \" FROM fonts WHERE id=\'$fonts_id\'\");
 
  while ($temparray=mysql_fetch_array($tempquery))
  {
    if (preg_match($preg,$temparray[$type]))
    {
    $fonts2[$a] = $temparray[$type];
    $a++;
    }
  }
  }[/quote]

this is also feasible, I believe, however, using this method, I am restricted by the results of my query, which are limited.
for example, if I searched for blah, and 5 fonts contained \"blah\"...
these fonts would rarely appear close to one another in an ordered list, hence if my function returns 20 results ONLY (remember my query is not limited at point of execution, meaning, returning 20 results ragardless of their fnames and search criteria)... all these font names containing \"blah\" may not appear together, making the function useless /cry.gif\' class=\'bbc_emoticon\' alt=\':(\' />



Here\'s what I\'ve considered as alternatives:

using a while loop, and some sort of array to relate all the fonts attributes, filter each existing array ($fnames,$fcreators,$fcreatoepages...) to match search criteria, this will take a while, and probably have a more convenient alternative.

make one huge multidimensional array... not sure how this would work right now, but a possibility none-the-less

somehow change the query, or add more, to make my life a lot easier and filter the results for me.

right now my mind has fried, so over to you guys /blum.gif\' class=\'bbc_emoticon\' alt=\':P\' /> (by the way, if you read all the way to the end of this post, heres a cookie!!! /smile.gif\' class=\'bbc_emoticon\' alt=\':)\' /> )[/b]

KillaFonts Searching Function

Posted: Sat Nov 06, 2004 10:58 am
by Scott
If regex doesn\'t work have you tried an SQL LIKE query? 10x simplier and it usually works well.

KillaFonts Searching Function

Posted: Sat Nov 06, 2004 11:42 am
by ner0
[b]I\'ve tried the mysql queries, thing is, I need it to get the id\'s of the fonts... so if a query like

[quote]SELECT id FROM fonts WHERE $searchtype MATCHES *$searchcriteria*[/quote]
that\'d be great, but i\'ve yet to find it /blum.gif\' class=\'bbc_emoticon\' alt=\':P\' />, only thing I\'ve found so far is MATCH, so i\'m looking through that to see if it works.
thnx for the reply scott /good.gif\' class=\'bbc_emoticon\' alt=\'(Y)\' />[/b]

KillaFonts Searching Function

Posted: Sat Nov 06, 2004 11:48 am
by ner0
[b]Ok, I think this MATCH could be what i\'ve been looking for...
heres an example query I found on the mySQL website:

[quote]SELECT * FROM quotes_table WHERE MATCH (quote) AGAINST (\'\"mangé\"\' IN BOOLEAN MODE)[/quote]

I think that looks perfect for my situation...

will try it now *crosses fingers*
[/b]