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 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 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 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.