Derleek Posted July 3, 2008 Share Posted July 3, 2008 I always run into this problem and i'm curious what would be the most efficient way to approach it. I have to select up to 65 names from a database and display them in 10 different drop down menu's. would it be more efficient to run a bit of code 650 times code: (i am not sure if the MySQL stuff is right, i'm new and experimenting ) <? //QUERY to set the rider ID for pre-entry list of race $query = "SELECT racer_id FROM race_racer WHERE race_id = $race_id AND class_id = $class_id"; $result = mysql_query($query) or die(mysql_error()); $R_id = array(); while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $R_id= $row['racer_id']; $q=0; $sql = "SELECT name FROM Racers WHERE racer_id = $r_id"; $result = mysql_query($sql) or die(mysql_error()); $row = $result; $name =$row; } ?> or store all of the names into an array and go through the array 10 times. Once again i'm relatively new to the php/MySQL realms so go easy on me Link to comment https://forums.phpfreaks.com/topic/113105-efficiency-question/ Share on other sites More sharing options...
lemmin Posted July 3, 2008 Share Posted July 3, 2008 There is no reason to put the data into an array when you have it in a result set. Once you have the result set, loop through it 10 times, as you would an array. You can use mysql_data_seek to set it back to the beginning: http://www.php.net/manual/en/function.mysql-data-seek.php Link to comment https://forums.phpfreaks.com/topic/113105-efficiency-question/#findComment-581017 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.