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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:27:21+00:00 2026-06-04T17:27:21+00:00

I’m looking for a simple way using php and javascript, to print a php

  • 0

I’m looking for a simple way using php and javascript, to print a php variable at the top of the page, and only once the page has loaded and run through a while loop.

Basically, I have a while loop that goes through my database, and prints out a row in a table with a users details.
Each time it finds a user, it adds 1 to a variable that is declared at the beginning of the page.

This is my basic way of counting how many users have been found after a search.

I then print out the variable to inform me.
The only issue, is that I can only print the variable after the loop has fiished, meaning it has to be at the bottom of my page and underneath the table. This is stupid, as I then have to scroll to the bottom of a long table to find the number.

Is there A way that once the loop has finished, and set the count as a variable, I can then have a script go back and print the variable above the table?

Many thanks for any advice you guys can offer.

Cheers, Eds

EDIT: added code example:

<?php
$count = '0';
//Print all users with similar names
while($row = mysql_fetch_assoc($result))
{
//Start the form for each user to enable editing, along with row onhover colour
echo "<form method='post' action='editor.php'>
    <tr class='tablehover'>";
//Depending on searchby, change which column is bold. Helps pick out users
if($searchby == 'username') {
    echo "<td><div class='userhighlight'>".$row['Username']."</div></td>";
}
else {
    echo "<td>".$row['Username']."</td>";
}
if($searchby == 'firstname') {
    echo "<td><div class='userhighlight'>".$row['First Name']."</div></td>";
}
else {
    echo "<td>".$row['First Name']."</td>";
}
if($searchby == 'lastname') {
    echo "<td><div class='userhighlight'>".$row['Last Name']."</div></td>";
}
else {
    echo "<td>".$row['Last Name']."</td>";
}
if($searchby == 'office') {
    echo "<td><div class='userhighlight'>".$row['Office']."</div></td>";
}
else {
    echo "<td>".$row['Office']."</td>";
}
if($searchby == 'lastlogin') {
    echo "<td><div class='userhighlight'>".$row['Last_Login']."</div></td>";
}
else {
    echo "<td>".$row['Last_Login']."</td>";
}

//Set ID of found user
$id = $row['User ID'];
//Create query to load user roles
$roleqry = "SELECT * FROM `site roles` WHERE `User ID`='$id'";
$roleresult = mysql_query($roleqry);
//Set $roles to gather roles
while($roles = mysql_fetch_assoc($roleresult)) {

//Echo out the rest of the user details into the table
echo "<td>".$roles['Admin']."</td>";
echo "<td>".$roles['Create User']."</td>";
echo "<td>".$roles['Edit User']."</td>";
echo "<td>".$roles['SandS']."</td>";
echo "<td>".$roles['SandS Admin']."</td>";
//Echo the hidden ID field, for editing, along with the edit button
}
echo "<td><input type='text' name='id' size='1' value='".$row['User ID']."' readonly style='visibility:hidden;width:1px;'>
            <input type='submit' value='Edit'></td></tr></form>";
echo "<tr><td colspan='11'><hr /></td></tr>";
$count = $count + 1;
}
?>

This obviously ends the loop. But I now have no choice, but to echo the set variable $count after this, putting it at the bottom of the page:

echo "<br />".$count." user's found";
  • 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-06-04T17:27:23+00:00Added an answer on June 4, 2026 at 5:27 pm

    You can simply count the number of rows in the result set using mysql_num_rows() right?
    Then you could set the count before the table begins:

    Count: <?php echo mysql_num_rows($result) ?>
    <table>...</table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm making a simple page using Google Maps API 3. My first. One marker
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
I would like to count the length of a string with PHP. The string

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.