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']; } Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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... Quote Link to comment 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. 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.