Link to home
Start Free TrialLog in
Avatar of jeffparis
jeffparis

asked on

Can you improve this code for performance? (mysql/php)

Is there a more efficient means to query new posts, like my code below? It works well, but is a bit harsh on the CPU.




$i = 0;
$get_items = "SELECT b.blog_id, b.author_id, b.date, b.subject, b.views, u.user_id, u.username, u.valid, u.category ";
$get_items .= "FROM nlb3_blogs AS b LEFT JOIN nlb3_users AS u ON b.author_id = u.user_id ";
$get_items .= "WHERE b.author_id = u.user_id AND b.access != 4 AND u.category != 0 ORDER BY b.date DESC LIMIT 50";
$get_table_data = mysql_query($get_items) or die("MySQL Error #".mysql_errno().": ".mysql_error()."\nQuery:");

      if (mysql_num_rows($get_table_data)<1) {

      $ets->recent_blogs2 = 'No New Blogs';

} else {
            while ($row = mysql_fetch_array($get_table_data)) {
            stripslashes_array( $row );
            $ets->recent_blogs2[$i]->username       = stripslashes($row['username']);
            $ets->recent_blogs2[$i]->user_id      = $row['user_id'];
            $ets->recent_blogs2[$i]->subject      = stripslashes($row['subject']);
            $ets->recent_blogs2[$i]->views            = $row['views'];
            $ets->recent_blogs2[$i]->category     = $row['category'];
            $ets->recent_blogs2[$i]->blog_id     = $row['blog_id'];
            $ets->recent_blogs2[$i]->date     = date("F j, Y, g:i a", $row['date']);
            $i++;
            }
            
      }
ASKER CERTIFIED SOLUTION
Avatar of AEG-IT
AEG-IT

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jeffparis
jeffparis

ASKER

Actually, that does help, thanks. I have brain fry right now and could not think of any optimizations. Even just a 5% improvement is worth it:)