ale1981 Posted July 19, 2007 Share Posted July 19, 2007 I have always wondered if there is a way of doing a quicker select statement than the one below; $userID = $_GET['userID']; $result = mysql_query("SELECT name FROM users WHERE userID = $userID"); $row = mysql_fetch_row($result); echo $row[0]; Can this query be shortened for simple queries like this one where I just want to retrieve a single field from one row? Link to comment https://forums.phpfreaks.com/topic/60733-shorter-select-statements/ Share on other sites More sharing options...
metrostars Posted July 19, 2007 Share Posted July 19, 2007 That is simple. You can't get it any more simple than that. unless you want to put LIMIT 0, 1 on the end, although it isn't necessary if userid is a primary field anyways. Link to comment https://forums.phpfreaks.com/topic/60733-shorter-select-statements/#findComment-302125 Share on other sites More sharing options...
ale1981 Posted July 19, 2007 Author Share Posted July 19, 2007 Yes I know it is simple, its just i have always wondered if there is a simpler way! Thanks for your reply. Link to comment https://forums.phpfreaks.com/topic/60733-shorter-select-statements/#findComment-302129 Share on other sites More sharing options...
ale1981 Posted July 19, 2007 Author Share Posted July 19, 2007 I have actually found an easier way (well for me anyway!); $userID = $_GET['userID']; $result = mysql_query("SELECT userName FROM users WHERE userID = $userID"); $userName = mysql_result($result, 0); echo $userName; ... not quite the same!! Link to comment https://forums.phpfreaks.com/topic/60733-shorter-select-statements/#findComment-302158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.