Forum Moderators: coopster

Message Too Old, No Replies

FULLTEXT searching not working

         

matun

12:38 pm on May 7, 2007 (gmt 0)

10+ Year Member



Hello all,

I have this database I want to provide a search engine for. So, for my testing purposes, I set up a small form with one textfield which contains a "post" directive and call rezultati.php for searching and displaying results, but it outputs the following error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\hshome\johndoe\example.com\kristo\rezultati.php on line 124

The line 124 says this:

while ( $row = mysql_fetch_array($subjekti))
and it seems to me that nothing is wrong with this line of code. The whole results.php is like this:

<?php
$srckveri=$_GET['srckveri'];

$db=mysql_connect ("localhost", "matun", "letmein") or die ('Neuspješno spajanje na bazu: ');
mysql_select_db ("mydatabase");

//$kveri = "LIKE '%$srckveri% '";

function div ($a, $b) {return ($a-$a%$b)/$b;}
$po_stranici = 20; // broj podataka po stranici
$vijesti = mysql_query("SELECT COUNT(MBO) AS broj FROM mydatabase");
$r = mysql_fetch_array($vijesti, MYSQL_ASSOC);
$broj_redova = $r['broj'];
$broj_stranica = div($broj_redova+$po_stranici-1, $po_stranici);
$stranica = @$_GET['str'];
if (!isset($stranica)) $stranica = 1; else $stranica = intval($stranica);
if ($stranica < 1 ¦¦ $stranica > $broj_stranica) $stranica = 1;
$x = ($stranica - 1) * $po_stranici;

/* konacni upit koji daje trazene podatke i dodano power trazenje putem FULLTEXT f-je mysqlu. Sortiramo po relevantnosti.*/

$subjekti=@mysql_query("SELECT * FROM mydatabase WHERE MATCH (MBO, dugiNaziv, kratkiNaziv, regBrOrg, brUpisaReg, datumRegUp, imeZupanije, mbGrada, Grad, mbNaselja, Naselje, postanskiBr, Adresa, kucniBr, NKD, datReg, tel1, tel2) AGAINST ($srckveri) LIMIT $x, $po_stranici");

// Cupaj vijesti iz baze, redak po redak:
while ( $row = mysql_fetch_array($subjekti))
{
$kratak_sadrzaj = $row['kratkiNaziv'];
$ulazni_datum = $row['datReg'];
$format = 'd.m.Y.';
$izlazni_datum = date($format, strtotime($ulazni_datum));
echo ('<tr><td align="left" class="title"></td><td align="right" class="datumiNaNovostima">Ukupno rezultata: '.$broj_redova.'</td></tr>
<tr><td align="left" class="title">'.$row['kratkiNaziv'].'</td><td align="right" class="datumiNaNovostima">'.$izlazni_datum.'</td></tr>
<tr><td colspan="2" valign="top" class="tijelo">'.nl2br($row['dugiNaziv']).'</td></tr>
<tr><td colspan="2" valign="top" class="tijelo">'.$row['Grad'].'</td></tr>
<tr><td colspan="3" align="right" class="tijelo"><a href="detaljnije.php?ID='.$row['MBO'].'">Detalji</a></td></tr>
<tr><td colspan="3" class="separator"></td></tr>');
}?>
</table><div class="paginacija" align="center">
<? // prikaz linkova na ostale stranice
for ($i = 1; $i <= $broj_stranica; ++$i)
if ($i == $stranica) echo "<b>[$i]</b> ";
else echo " <a href=\"rezultati.php?&str=$i\">$i </a>";
?>

Prior to that I hit my database with the following sql command:

ALTER TABLE mytable ADD fulltext(fieldName1,fieldName2,...)"

What am I doing wrong?

[edited by: eelixduppy at 2:00 pm (utc) on May 7, 2007]
[edit reason] use example.com [/edit]

joelgreen

3:52 pm on May 7, 2007 (gmt 0)

10+ Year Member



Add following after the $subjekti=@mysql_query...

echo mysql_error();

It looks like you have an error in the sql clause.

StupidScript

11:03 pm on May 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, remove the '@' from $subjekti=@mysql_query to see any mysql_error() output.

Your "error" says that the query did not produce an array ... which usually means that nothing matched your query. It looks like the query ran okay (would have been a different error if the problem was with the query syntax), but it just didn't produce anything.