1
$query_count="SELECT COUNT(*) FROM table";
$result_count = mysql_query($query_count);
$final_count=mysql_fetch_array($result_count);
echo $final_count[0];

This cause the website to "loop" (page never loads, browser runs out of memory). any idea how to do it?

2
  • 3
    Your website "loops?" What do you mean? Does the page never load? Commented Jul 31, 2011 at 1:01
  • exactly, browser takes most of my RAM. Commented Jul 31, 2011 at 1:02

3 Answers 3

1

I think it should be :

$query_count="SELECT COUNT(*) FROM table";
$result_count = mysql_query($query_count);
$final_count=mysql_fetch_row($result_count);
echo $final_count[0];
Sign up to request clarification or add additional context in comments.

2 Comments

There's nothing in the original code that will 'loop', but in the original code $final_count would be an array and echo $final_count would simply print 'Array'. @Blackie123: Are you sure there aren't any infinite loops elsewhere in your script?
@Blackie123 I simply used mysql_fetch_row as we always expect one row, you can continue to use mysql_fetch_array if you want. The main difference is the last line. Chris is correct in pointing out that there is nothing in this part of the code which would cause the the page to go into an infinite loop, something else seems to be an issue.
0

try replacing echo $result_count; with echo $final_count;

EDIT - another option:

$query_count="SELECT COUNT(*) FROM table";
$result_count = mysql_query($query_count);
$final_count=mysql_fetch_field($result_count, 0);
echo $final_count;

1 Comment

that one causes the loop but how shall I find out the count other then that?
0

Try:

$query_count="SELECT COUNT(*) FROM table";
$result_count = mysql_query($query_count);
echo mysql_result($result_count, 0, 0);

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.