Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3332754
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:43:18+00:00 2026-05-17T23:43:18+00:00

While I build a web page in My PHP web application, My Connection works

  • 0

While I build a web page in My PHP web application, My Connection works ok but When I want to get the count of rows of the SELECT Statement I used in my query, It gives me -1 !! although my result set has about 10 rows.

I would like to get the actual number of result set rows.
I searched the PHP Manual & documentation but I do not find a direct way like a Count function or something like that.

I wonder if I have to make a Count(*) SQL Statement in another query and attach it to my Connection to get the Count of Rows ?

Does any one knows an easy and direct way to get that ?

the odbc_num_rows function always gives -1 in result so I can not get the actual number of rows.

My Programming langauge is PHP and My Database Engine is Sybase and The Way to connect to Database is ODBC.

Here are you the Code I used:-

<?PHP

//PHP Code to connect to a certain database using ODBC and getting information from it

//Determining The Database Connection Parameters
$database = 'DatabaseName';
$username = 'UserName';
$password = 'Password';

//Opening the Connection
$conn = odbc_connect($database,$username,$password);

//Checking The Connection
if (!$conn)
{
exit("Connection Failed: " . $conn);
}

//Preparing The Query
$sql = "SELECT * FROM Table1 WHERE Field1='$v_Field1'";

//Executing The Query
$rs = odbc_exec($conn,$sql);

//Checking The Result Set
if (!$rs)
{
exit("Error in SQL");
}

echo "<p align='Center'><h1>The Results</h1></p>";

while ( odbc_fetch_row($rs) )

{
  $field1 = odbc_result($rs,1);
  $field2 = odbc_result($rs,2);
  $field3 = odbc_result($rs,3);
  echo "field1 : " . $field1 ;
  echo "field2 : " . $field2 ;
  echo "field3 : " . $field3 ;
}

$RowNumber = odbc_num_rows($rs);

echo "The Number of Selected Rows = " . $RowsNumber ; 

//Closing The Connection
odbc_close($conn);

?>

Thanks for your Help 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:43:18+00:00Added an answer on May 17, 2026 at 11:43 pm

    odbc_num_rows seems to be reliable for INSERT, UPDATE, and DELETE queries only.

    The manual says:

    Using odbc_num_rows() to determine the number of rows available after a SELECT will return -1 with many drivers.

    one way around this behaviour is to do a COUNT(*) in SQL instead. See here for an example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While answering Static class variables in Python I noticed that PythonWin PyWin32 build 209.2
Is there a way to get struts 2 (using tiles) to build the whole
While Ctrl X works fine in vim under windows, Ctrl A selects all (duh).
I've bumped into a problem while working at a project. I want to crawl
I need to build a visual editor in C#. Given a piece of PHP
commonly on say PHP or other web frameworks getting the total response time is
I have two arrays built while parsing a text file. The first contains the
While the C# spec does include a pre-processor and basic directives (#define, #if, etc),
While going through university and from following the development of SO, I've heard a
While I've seen rare cases where private inheritance was needed, I've never encountered a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.