Jump to content

Please help improve efficientcy


EchoFool

Recommended Posts

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
Share on other sites

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.