EchoFool Posted July 6, 2010 Share Posted July 6, 2010 Hey, I have a PHP script which is called very frequently, and would like to make it as efficient as possible - so was wondering if you can give me some points on this script on how i can make it more efficient for my server. <?php If(!isset($_SESSION['ID'])){ echo '1'; $SELECT = mysql_query("SELECT id from logs WHERE id > '{$_SESSION['ID']}' ORDER BY id DESC LIMIT 1") or die(mysql_error()); $row = mysql_fetch_assoc($SELECT); If($row){ $_SESSION['ID'] = $row['id']; } }Else{ $SELECT = mysql_query("SELECT id from logs WHERE id > '{$_SESSION['ID']}' ORDER BY id DESC LIMIT 1") or die(mysql_error()); $row = mysql_fetch_assoc($SELECT); If($row && $row['id'] > 0){ echo '1'; $_SESSION['ID'] = $row['id']; }else{ echo $_SESSION['ID']; } } ?> The idea behind it is simply to set the last id of the table to the session. Was hoping some one could see if this is the best way to do it. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/206830-please-help-improve-efficientcy/ Share on other sites More sharing options...
ignace Posted July 6, 2010 Share Posted July 6, 2010 $result = mysql_query("SELECT id FROM logs WHERE id > {$_SESSION['ID']} ORDER BY id DESC LIMIT 1"); if(false !== $result && 0 !== mysql_num_rows($result)) { list($id) = mysql_fetch_row($result); echo $id; } else { echo $_SESSION['ID']; } set the last id of the table to the session mysql_query('INSERT INTO ..'); $_SESSION['ID'] = mysql_insert_id(); Quote Link to comment https://forums.phpfreaks.com/topic/206830-please-help-improve-efficientcy/#findComment-1081805 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.