Link to home
Start Free TrialLog in
Avatar of campanal
campanal

asked on

problem with odbc_num_rows

hi everybody,

I have a problem with the count of the rows  after a query.
I work with a DB MS Access and I know that odbc_num_rows doesn't work.

I thied this:


$sql1 = "SELECT COUNT(*) FROM contribuente where con_numero_controllo in (".$sql.") as righe";
     $sql_result = odbc_prepare($cn,$sql1) or die("ERROR");
     odbc_execute($sql_result) or die("ERROR");
     $rc = odbc_fetch_into($sql_result, $my_array);
     echo ("Total rows: " . $my_array[0]);
     odbc_free_result($sql_result);


the subselect  $sql is:

$sql="select con_numero_controllo as N_controllo,con_numero_registro as N_registro, con_cognome as Cognome, con_nome as Nome,con_data_nascita as Data_nascita
from contribuente
where (1=1) and (con_cognome like'ca%')";

con_cognome is a choice that the uses makes. for example i write "ca" and it gives me back the all name that gegin with ca.

there is something wrong in the the subselect bacause it can't perform it.

Can anyone help me please..

thanks in advance



Avatar of Karitz
Karitz

If you want to get the number of rows you use something like

$sql1 = "SELECT COUNT(*) as righe FROM contribuente where con_numero_controllo in (".$sql.")";

but if you want to get all the results and put them in an array you use

$sql1 = "SELECT * FROM contribuente where con_numero_controllo where (1=1) and (con_cognome like'ca%')";


this way you are sure you are getting all the rows (of data) in your table
Avatar of campanal

ASKER

But I only want the number of rows because if the result is > 2 then I show a messagge..
ASKER CERTIFIED SOLUTION
Avatar of Karitz
Karitz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks for the help