Jump to content

Recommended Posts

Hello guys, I need a little help to explain how to limit while loops !

 

if I want to get an info from the MySQL, using php script, and I need this info to be the last four (for example) desc result! how to get them?

 

an example:


<?php
// this is only an example I wrote now, please don't focus on other issues, teach me how to limit a while() loop.


include("configuration.php");


// let's say I need to see the last four registrants (the most recent)


$samoi = "SELECT username FROM users WHERE id < 4 ORDER BY registation_time desc"; // is this correct stament? I mean id < 4 but I need the last 4 registrants ! It dives me crazy !
$samoi_SQL = mysql_query($samoi);

    while($phpfreaks = mysql_fetch_assoc($samoi_SQL))

           {
              echo $phpfreaks['username'];
              echo "<br />";
           }

?>


 

I really appreciate your help

Link to comment
https://forums.phpfreaks.com/topic/142910-solved-limit-the-while-results/
Share on other sites

Thank you all guys, I havn't tried it, but I just want to learn, because when ever I needed to pull data of the recent entries I wonder how to do it.

 

so doing this by adding

LIMIT 0,3

to the statement of the MySQL, is that right?

 

:)

 

feeling happy !

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.