Omzy Posted August 19, 2009 Share Posted August 19, 2009 I've got code as follows: $query="SELECT * FROM customer WHERE id='$_GET['id']'"; $results = mysql_query($query); while($row=mysql_fetch_array($results, MYSQL_ASSOC)) { //assign all the $row variables; } Now because the ID field is unique, it will always bring back one record only, which is just what I need it to do. This code works fine, but I want to know is this the most efficient way of doing it? Should I put in a "LIMIT" parameter on the SQL query, do I really need to use a WHILE loop? Quote Link to comment https://forums.phpfreaks.com/topic/170999-solved-code-that-brings-back-one-record-only/ Share on other sites More sharing options...
onedumbcoder Posted August 19, 2009 Share Posted August 19, 2009 $query="SELECT * FROM customer WHERE id='$_GET['id']'"; $results = mysql_query($query); $row=mysql_fetch_array($results, MYSQL_ASSOC); echo $row['id']; Quote Link to comment https://forums.phpfreaks.com/topic/170999-solved-code-that-brings-back-one-record-only/#findComment-901861 Share on other sites More sharing options...
KevinM1 Posted August 19, 2009 Share Posted August 19, 2009 I've got code as follows: $query="SELECT * FROM customer WHERE id='$_GET['id']'"; $results = mysql_query($query); while($row=mysql_fetch_array($results, MYSQL_ASSOC)) { //assign all the $row variables; } Now because the ID field is unique, it will always bring back one record only, which is just what I need it to do. This code works fine, but I want to know is this the most efficient way of doing it? Should I put in a "LIMIT" parameter on the SQL query, do I really need to use a WHILE loop? You don't need a loop if you only need one row. Quote Link to comment https://forums.phpfreaks.com/topic/170999-solved-code-that-brings-back-one-record-only/#findComment-901862 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.