Solved

problem with odbc_num_rows

Posted on 2003-11-04
4
521 Views
Last Modified: 2013-12-12
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
Comment
Question by:campanal
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:Karitz
ID: 9677013
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
 

Author Comment

by:campanal
ID: 9677042
But I only want the number of rows because if the result is > 2 then I show a messagge..
0
 
LVL 5

Accepted Solution

by:
Karitz earned 50 total points
ID: 9677640
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
 

Author Comment

by:campanal
ID: 9678245
thanks for the help
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now