Solved

problem with odbc_num_rows

Posted on 2003-11-04
4
534 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Underscores vs. Directory separators 5 46
Get data from two MySQL tables 6 65
How do I allow for non standard CSV file 9 45
Why is my select returning NaN 23 37
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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