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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:12:46+00:00 2026-05-25T10:12:46+00:00

I have seen people use rowCount like this… if ($q -> rowCount() < 1)

  • 0

I have seen people use rowCount like this…

if ($q -> rowCount() < 1) {
   ....
}

Which is how I use it for most part my question is though if you have multiple elseif statements is it better to store it in a variable as the rowCount will not be called more than once?? Like this…

if (isset($_GET['action']) && $_GET['action'] === 'addhotlink') {
    $q = $dbc -> prepare("SELECT * FROM hotlinks WHERE id = ?");
    $q -> execute(array($details['id']));
    $result = $q -> rowCount();
    if ($result < 3) {
        echo '<p>Choose a name for your hotlink (max 15 characters):</p><p><form action="/success?action=hotlink" method="post"><input type="text" name="link_name" maxlength="15" /></p><input type="hidden" name="addhotlink" value="' . $_SERVER['HTTP_REFERER'] . '" /><p><input id="submit" type="submit" value="Add Hotlink" /></p></form>';
    }
    elseif ($result < 10 && $details['subscriber'] > 0) {
        echo '<p>Choose a name for your hotlink (max 15 characters):</p><p><form action="/success?action=hotlink" method="post"><input type="text" name="link_name" maxlength="15" /></p><input type="hidden" name="addhotlink" value="' . $_SERVER['HTTP_REFERER'] . '" /><p><input id="submit" type="submit" value="Add Hotlink" /></p></form>';
    }
    elseif ($result > 9 && $details['subscriber'] > 0) {
        echo '<p>You have already used your maximum number of 10 hotlinks.</p>';
    }
    else {
        echo '<p>You have already used your maximum amount of hotlinks allowed for non subscribed members.</p><p>To get more please <a href"#">subscribe</a>.</p>';
    }

Which is better and why??

  • 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-25T10:12:47+00:00Added an answer on May 25, 2026 at 10:12 am

    If you just need the number of rows and not the real data, you should prefer a simple “SELECT COUNT(*)”.
    AFAIK rowCount() is cached anyway, so there is no need to store it in a local variable.

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

Sidebar

Related Questions

I have seen different people use different types of braces/brackets for this. I tried
Simple question... I have seen people tell me to use \r\n in various places
A quick question about best practice with PHP classes. I have seen people use
I have seen some instances where people will say you have to use JS
I have seen people use GO statement between batches of SQL code, but AFAICS
I have seen that people use <div id=name> rather than <div id=name> is that
I have seen people often use a separate table to store relations between tables.
I have seen people use addition where a bitwise OR would be more conceptually
I have seen this question asked all over the internet and answered in many
I have seen people say that it is bad form to use catch with

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.