Ciao a tutti!!!

Questa query mi restituisce un errore nella riga:

$rows = mysql_num_rows($query);

Questo è l'errore
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\programmi\apache group\apache\test\igratis\prove\untitled2.php on line 505


Questa è la query:
$sql=" SELECT * ";
$sql.=" FROM (annunci INNER JOIN utenti ON annunci.IDutente = utenti.IDutente ";
$sql.=" WHERE Testo LIKE '%%%$cerca%%%' and IDcateg=$tipologia2 ";
$sql.=" ORDER BY DataIns DESC , IDannuncio DESC ";
$query = mysql_query($sql);
$rows = mysql_num_rows($query);
$sql.=" LIMIT $limit, $annunci_pagina";
$query = mysql_query($sql);

Qualcuno mi sa dire il perchè??
Dove sto sbaglaindo?