0

In my scrolling feed model i'm returning the number of users in the database , and the last 50 users added to the database in ascending order. For some reason , the last 50 users are not returning.
My model code is the following:

<?php

//display total records in db


//add html
echo '<link rel="stylesheet" href="assets/css/feed.css" /><div id="feed"<marquee>
<B>Available Accounts: </B>';

//fetch amount of users
$usercount="SELECT user_name FROM store";
if ($res=mysqli_query($conn,$usercount))
  {
  // Return the number of rows in result set
  $rowcount=mysqli_num_rows($res);
  printf("%d",$rowcount);
  // Free result set
  mysqli_free_result($res);
  } 

 //add html 
 echo 
  '<b>' . 
  ' . . . Last 50 Added Usernames . . .</b>';
//last 50 added to the database
$lastusers = mysqli_query
  ("SELECT user_name FROM (
  SELECT * 
  FROM store 
  ORDER BY user_id DESC
  LIMIT 50
) AS store ORDER BY user_id ASC");

$row = mysqli_fetch_array($lastusers);
echo $row['user_name'];

echo '</marquee></div>';


?>
2
  • your query is incorrect Commented Aug 20, 2017 at 14:10
  • which part of it? if i test the query in the database it works fine Commented Aug 20, 2017 at 14:11

1 Answer 1

3

Try this out!

<?php


//MySQLi information

$db_host     = "localhost";
$db_username = "username";
$db_password = "password";

//connect to mysqli database (Host/Username/Password)
$connection = mysqli_connect($db_host, $db_username, $db_password) or die("Error " . mysqli_error());

//select MySQLi dabatase table
$db = mysqli_select_db($connection, "table") or die("Error " . mysqli_error());


//fetch amount of users
$usercount = mysqli_query($connection, "SELECT user_name FROM store");
$rows      = mysqli_num_rows($usercount);
echo $rows . " Users!" . "<br>";


//last 50 added to the database
$row = mysqli_query($connection, "SELECT * FROM store LIMIT 50");

while ($lastusers = mysqli_fetch_array($row)) {
    echo $lastusers['user_name'] . "<br>";
}

Tested and works fine, here is an example! enter image description here

Good luck!

Sign up to request clarification or add additional context in comments.

2 Comments

WOW all i needed was a while loop. THANKS
@Pacified Enjoy, please accept the answer by ticking the correct button ;)

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.