arnel9 Posted October 8, 2003 Share Posted October 8, 2003 is there any ways to optimize php codes. Example: $id=mysql_connect(\"host\", \"username\", \"password\") or die(mysql_error()); mysql_select_db(\"databasename\", $id); $rs = mysql_query(\"Select name from table_name\", $id) or die(mysql_error()); echo \"<select name=\'names\'>\"; do { echo \"<option value=\'\" . $row[\'name\'] . \"\'>\" . $row[\'name\'] . \"</option>\"; } while($row=mysql_fetch_array($rs)); the code above sometimes gives me error \"Page cannot be displayed\" because the record that i try to retreive is more than 1000. :?: Quote Link to comment Share on other sites More sharing options...
metalblend Posted October 8, 2003 Share Posted October 8, 2003 ..not too sure if this bit of code will speed the process, but is shorter and (in my opinion) the safer way to go: <?php $id=mysql_connect(\'host\',\'username\',\'password\') or die(mysql_error()); mysql_select_db(\'databasename\',$id) or die(mysql_error()); $rs = mysql_query(\'SELECT name FROM table_name\',$id) or die(mysql_error()); while($row = mysql_fetch_array($rs,MYSQL_ASSOC)) echo \'<option value=\'\' . $row[\'name\'] . \'\'>\' . $row[\'name\'] . \'</option>\'; ?> Hope that helps. Quote Link to comment Share on other sites More sharing options...
arnel9 Posted October 8, 2003 Author Share Posted October 8, 2003 oh.. thanks... i searched some ideas in optimizing php code in google and i try the tips that i\'ve found and it works fast..!! i make some optimization in the code that i given earlier base on the tips and i come up with this: [php:1:6c213089bb]<?php ob_start(); $id=mysql_connect(\"host\", \"username\", \"password\") or die(mysql_error()); mysql_select_db(\"databasename\", $id); $rs = mysql_query(\"Select name from table_name\", $id) or die(mysql_error()); $opt = \"<select name=\'names\'>\"; do { $opt.= \"<option value=\'\" . $row[\'name\'] . \"\'>\" . $row[\'name\'] . \"</option>\"; } while($row=mysql_fetch_array($rs)); echo $opt . \"</option>\"; unset($opt); ob_end_flush(); ?>[/php:1:6c213089bb] 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.