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 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(); Link to comment https://forums.phpfreaks.com/topic/206830-please-help-improve-efficientcy/#findComment-1081805 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.