0

In my website, All I pretty much do is show the fullnames of the users that submitted a form from the database and when a admin clicks a name, it just gives the clicked users email. My question is, how can I arrange the list of names to where it gives me the newest names on top and older on bottom? I have a timestamp cell in there that documents the timestamp when the user submits a form. Here is my code

<?php


require_once('db_login.php');

    $stmt = $handler->prepare("SELECT * FROM formdata");

    $stmt->execute();
    while($result = $stmt->fetch()){

       $userid = $result['user_id'];
        echo "<a href='speaker_apps.php?infoid={$userid}'>". $result['fullname']."</a></br>";
    }

if(isset($_GET['infoid'])){


    $stmt = $handler->prepare("SELECT * FROM formdata where user_id='".$_GET['infoid']."'");
    $stmt->execute();
    $row = $stmt->fetch();
    echo "<p>id =".$row['email']."</p></br>";
}


?>
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Jagr
  • 484
  • 2
  • 11
  • 31
  • Be aware that your prepare() is a straw plane that never flies. You must use a real [prepared statement](https://phpdelusions.net/pdo#prepared) – Your Common Sense Feb 17 '18 at 18:28

1 Answers1

1

ORDER your results:

$stmt = $handler->prepare("SELECT * FROM formdata ORDER BY your_time_field DESC");
u_mulder
  • 54,101
  • 5
  • 48
  • 64