Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

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



0
campanal
Asked:
campanal
  • 2
  • 2
1 Solution
 
KaritzCommented:
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
0
 
campanalAuthor Commented:
But I only want the number of rows because if the result is > 2 then I show a messagge..
0
 
KaritzCommented:
I that case use

$sql1 = "SELECT COUNT(*) as righe FROM contribuente where where (1=1) and (con_cognome like'ca%')";
 $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);

this should give you the nyumber of rows

alternatively


$sql1 = "SELECT * FROM contribuente where con_numero_controllo where (1=1) and (con_cognome like'ca%')";
 $sql_result = odbc_prepare($cn,$sql1) or die("ERROR");
 odbc_execute($sql_result) or die("ERROR");

     $total=odbc_num_rows( $sql_result )
     echo ("Total rows: " . $total);
     odbc_free_result($sql_result);
0
 
campanalAuthor Commented:
thanks for the help
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now