scarhand Posted July 4, 2007 Share Posted July 4, 2007 I have these selections in 1 file that the user is able to configure themselves via a form in their control panel....I've got it all working but I was wondering if this is a good way of doing it or not... $adminsql = mysql_query("SELECT * FROM admin_user"); while($row = mysql_fetch_array($adminsql)) { $adminusername = $row['username']; $adminpassword = $row['password']; } $bandnamesql = mysql_query("SELECT * FROM config WHERE config_name = 'bandname'"); while($row = mysql_fetch_array($bandnamesql)) { $bandname = $row['config_value']; } $copyrightsql = mysql_query("SELECT * FROM config WHERE config_name = 'copyright'"); while($row = mysql_fetch_array($copyrightsql)) { $copyright = $row['config_value']; } Link to comment https://forums.phpfreaks.com/topic/58423-solved-is-this-an-efficient-sql-selection/ Share on other sites More sharing options...
Foser Posted July 4, 2007 Share Posted July 4, 2007 Might be me getting tired but im not totally sure what your trying to do. Link to comment https://forums.phpfreaks.com/topic/58423-solved-is-this-an-efficient-sql-selection/#findComment-289677 Share on other sites More sharing options...
radalin Posted July 4, 2007 Share Posted July 4, 2007 well, it's ok but you may try to use SELECT * FROM config WHERE config_name = 'bandname' OR config_name = 'copyright' Instead of two queries which will increase your performance a little bit. By the way you should had tried mysql section of this forum not php help section because this topic fits better there. Link to comment https://forums.phpfreaks.com/topic/58423-solved-is-this-an-efficient-sql-selection/#findComment-289682 Share on other sites More sharing options...
scarhand Posted July 4, 2007 Author Share Posted July 4, 2007 My bad! posting in MySQL forum instead... Link to comment https://forums.phpfreaks.com/topic/58423-solved-is-this-an-efficient-sql-selection/#findComment-289685 Share on other sites More sharing options...
Hypnos Posted July 4, 2007 Share Posted July 4, 2007 Things I did to make it more efficent: - 1 less MySQL query - No "SELECT *"s. Sepcified only the column names needed. - mysql_fetch_assoc instead of mysql_fetch_array. You aren't using column numbers as keys. <?php $adminsql = mysql_query('SELECT username, password FROM admin_user'); while($row = mysql_fetch_assoc($adminsql)) { $adminusername = $row['username']; $adminpassword = $row['password']; } $bandnamesql = mysql_query("SELECT config_value FROM config WHERE config_name = 'bandname'" . " OR config_name = 'copyright'"); while($row = mysql_fetch_assoc($bandnamesql)) { switch($row['config_value']) { case "bandname": $bandname = $row['config_value']; break; case "copyright": $copyright = $row['config_value']; break; } } You probably don't need that first while. But I wasn't sure if there were multiple results for that. Link to comment https://forums.phpfreaks.com/topic/58423-solved-is-this-an-efficient-sql-selection/#findComment-289696 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.