MDanz Posted December 11, 2009 Share Posted December 11, 2009 how do i do this with php? i know how to do queries/ loops, so i don't need help with that. how do i get entries that begin with a certain letter? Quote Link to comment https://forums.phpfreaks.com/topic/184718-list-all-records-in-database-starting-with-the-letter-a/ Share on other sites More sharing options...
MDanz Posted December 11, 2009 Author Share Posted December 11, 2009 i tried this and its not working... blank page <?php mysql_connect("localhost", "Master", "password"); mysql_select_db("Login"); $letter = htmlentities($_GET['search']); $user = mysql_query("SELECT * FROM Users WHERE username LIKE '$letter%' ORDER BY username")or die (mysql_error()); while($rowz = mysql_fetch_array($user)){ $username = $rowz['username']; echo "<font face='Courier New' font size=2px font color=#FBB917>$username</font>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/184718-list-all-records-in-database-starting-with-the-letter-a/#findComment-975164 Share on other sites More sharing options...
premiso Posted December 11, 2009 Share Posted December 11, 2009 Not really sure what is wrong, worked fine using my database information: <?php mysql_connect("localhost", "Master", "password") or trigger_error("Connection Failed: " . mysql_error()); mysql_select_db("Login") or trigger_error("Database Selection failed: " . mysql_error()); $letter = isset($_GET['search']) ? htmlentities($_GET['search']) : ''; $user = mysql_query("SELECT * FROM Users WHERE username LIKE '{$letter}%' ORDER BY username")or trigger_error ("SQL Failed: " . mysql_error()); while($rowz = mysql_fetch_assoc($user)){ $username = $rowz['username']; echo "<font face='Courier New' font size=2px font color=#FBB917>$username</font>"; } ?> Try that and see if it does any better, not sure if it will because the original way seemed fine on my server, so it could be a server issue. Quote Link to comment https://forums.phpfreaks.com/topic/184718-list-all-records-in-database-starting-with-the-letter-a/#findComment-975642 Share on other sites More sharing options...
Daniel0 Posted December 11, 2009 Share Posted December 11, 2009 What's the point of using htmlentities here? I assume you wanted to use mysql_real_escape_string. Quote Link to comment https://forums.phpfreaks.com/topic/184718-list-all-records-in-database-starting-with-the-letter-a/#findComment-975698 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.