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 6837351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:27:59+00:00 2026-05-26T23:27:59+00:00

I would like to get the number of rows that satisfies the condition. mysql_query(SELECT

  • 0

I would like to get the number of rows that satisfies the condition.

mysql_query("SELECT COUNT(*) FROM sid WHERE sid='".session_id()."'");

this one ignores the condition.

update:

$session = session_id();
$sql = "SELECT COUNT(*) as row_count FROM sid WHERE sid = '$session' ";
var_dump($r = mysql_query($sql));//resource(4) of type (mysql result) (1)
var_dump(mysql_fetch_assoc($r));
//array(1) { ["row_count"]=> string(1) "1" }  - this result is OK(2)

(1) resource(4) – I thought that 4 was the count

(2) mysql_real_escape_string($_SESSION['id']); gives 0

note:

I have changed from mysql_num_rows to this type of getting count because I thought it will return immediately the count and I dont have to write more lines to get this basic data.

  • 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-26T23:28:00+00:00Added an answer on May 26, 2026 at 11:28 pm

    The correct way of doing this is:

    $session = mysql_real_escape_string($_SESSION['id']);  <<-- Get the session id
    echo "debug: session_id = ".htmlentities($session);
    $sql = "SELECT count(*) as row_count FROM tablename WHERE sid = '$session' ";
    $result = mysql_query($sql);
    if (!$result) {
      die('error in query '.$sql.' error is: '.mysql_error());
    }
    //we only have 1 result
    $row = mysql_fetch_array($result);
    //always sanitize so you don't suffer XSS attacks when the query changes   
    //and the $row['x'] changes from an integer to a user-supplied string.
    $count = intval($row['row_count']);  
    echo "count is: ".$count;
    

    The table name and the column name can be the same, but in your case they probably are not.
    sid obviously stands for the field “session_id”, so you need to replace the first sid after FROM with your tablename.

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

Sidebar

Related Questions

I would like to get number of rows that have same date. But one
I am using SQL and I would like to count the number of rows
I have a number of links which I would like to get some information
I would like to get View instance that is used to display specific Preference
I would like to get a help from you all. The below is the
I have data that, in a normal query, would appear like this: Val1 Val2
I know this may sounds silly but I would like to create function that
We have a number of stored procedures in production that we would like to
Whats the fastest way to get an approximate count of number of rows of
I have a query like the following that returns the correct number of rows

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.