Solved

problem with odbc_num_rows

Posted on 2003-11-04
4
525 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

910 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

22 Experts available now in Live!

Get 1:1 Help Now