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_tab le_data)) {
stripslashes_array( $row );
$ets->recent_blogs2[$i]->u sername = stripslashes($row['usernam e']);
$ets->recent_blogs2[$i]->u ser_id = $row['user_id'];
$ets->recent_blogs2[$i]->s ubject = stripslashes($row['subject ']);
$ets->recent_blogs2[$i]->v iews = $row['views'];
$ets->recent_blogs2[$i]->c ategory = $row['category'];
$ets->recent_blogs2[$i]->b log_id = $row['blog_id'];
$ets->recent_blogs2[$i]->d ate = date("F j, Y, g:i a", $row['date']);
$i++;
}
}
$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
$ets->recent_blogs2 = 'No New Blogs';
} else {
while ($row = mysql_fetch_array($get_tab
stripslashes_array( $row );
$ets->recent_blogs2[$i]->u
$ets->recent_blogs2[$i]->u
$ets->recent_blogs2[$i]->s
$ets->recent_blogs2[$i]->v
$ets->recent_blogs2[$i]->c
$ets->recent_blogs2[$i]->b
$ets->recent_blogs2[$i]->d
$i++;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER