0

For the query below, I would like to set a variable called $totalcount equal to the count of all loginids in table called login. How can I do this?

Thanks in advance,

John

$sqlStrcount = "SELECT loginid FROM login";

1 Answer 1

1
$sqlQueryStr = "SELECT loginid FROM login";
$sqlQuery = mysql_query($sqlQueryStr);

$totalCount = mysql_num_rows($sqlQuery);

If you only need to count your records in login use this instead for performance reasons.

$sqlQueryStr = "SELECT COUNT(loginid) as totalCount FROM login";
$sqlQuery = mysql_query($sqlQueryStr);

$row = mysql_fetch_assoc($sqlQuery);
$totalCount = $row['totalCount'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.