Problem With Funcion Creating Error_log

Discussion in 'PHP' started by ZanM, Feb 9, 2013.

  1. #1
    Hello

    i am having some trouble with navigation on my wordpress site. Code is below. I mean everything is working fine, but error_log is constantly being updated with this:

    [12-Jan-2013 08:02:15] WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 for query SELECT COUNT(DISTINCT ID) FROM made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/theme/index.php'), include('/themes/theme/library/includes/featured-page.php'), wp_pagenavi

    Can you help me somehow please :(?

    Thank you in advance!

    function wp_pagenavi($before = '', $after = '', $prelabel = '', $nxtlabel = '', $pages_to_show = 5, $always_show = false) {
    global $request, $posts_per_page, $wpdb, $paged, $totalpost_count, $posts_per_page_homepage, $postno;
    if($posts_per_page_homepage)
    {
    $posts_per_page = $posts_per_page_homepage;
    }
    if(empty($prelabel)) {
    $prelabel  = '<strong>&laquo;</strong>';
    }
    if(empty($nxtlabel)) {
    $nxtlabel = '<strong>&raquo;</strong>';
    }
    $half_pages_to_show = round($pages_to_show/2);
    if (!is_single()) {
    if(is_tag()) {
    preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches);       
    } elseif (!is_category()) {
    preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches);   
    } else {
    preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches);       
    }
    $fromwhere = $matches[1];
    $numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
    }
    if($totalpost_count)
    {
    $numposts = $totalpost_count;
    }
    if($postno)
    {
    $numposts = $postno;
    }
    if($numposts > 1000000)
    {
    $numposts = 100;
    }
    $max_page = ceil($numposts /$posts_per_page);
    if(empty($paged)) {
    $paged = 1;
    }
    if($max_page > 1 || $always_show) {
    echo "$before <div class='Navi'>";;
    if ($paged >= ($pages_to_show-1)) {
    echo '<a href="'.get_pagenum_link().'">&laquo; '.FIRSTT.'</a>';
    }
    previous_posts_link($prelabel);
    for($i = $paged - $half_pages_to_show; $i  <= $paged + $half_pages_to_show; $i++) {
    if ($i >= 1 && $i <= $max_page) {
    if($i == $paged) {
    echo "<strong class='on'>$i</strong>";
    } else {
    echo ' <a href="'.get_pagenum_link($i).'">'.$i.'</a> ';
    }
    }
    }
    next_posts_link($nxtlabel, $max_page);
    if (($paged+$half_pages_to_show) < ($max_page)) {
    echo '<a href="'.get_pagenum_link($max_page).'">'.LASTT.' &raquo;</a>';
    }
    echo "</div> $after";
    }
    }
    PHP:

     
    ZanM, Feb 9, 2013 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    isn't a valid SQL query. It looks as if someone edited one of your files and screwed up. If you can't find it (if you edited anything, look there), upload all your Wordpress files (other than the config file) again. Or restore the site from a backup you made before the problem started.
     
    Rukbat, Feb 12, 2013 IP
  3. ZanM

    ZanM Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #3
    Thank you Rukbat! Is there any way I could easier try to locate the cause?
     
    ZanM, Feb 12, 2013 IP
  4. Sano000

    Sano000 Active Member

    Messages:
    52
    Likes Received:
    4
    Best Answers:
    5
    Trophy Points:
    53
    #4
    There is wrong value in $fromwhere which setting by $request. You can try add print_r($request).'<br />'.print_r($fromwhere); (only on your test server!) to find the problematic area in your code.
     
    Sano000, Feb 12, 2013 IP
  5. ZanM

    ZanM Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #5
    Hi Sano000. Sory for late reply. I was really sick for some time. Thank you very much for trying to help. This is what I get if I add the line you wrote:

    SELECT SQL_CALC_FOUND_ROWS  wordpress_posts.ID FROM wordpress_posts  INNER JOIN wordpress_term_relationships ON (wordpress_posts.ID = wordpress_term_relationships.object_id) WHERE 1=1  AND ( wordpress_term_relationships.term_taxonomy_id IN (200,210,220,230,240,250,260,270,280,290) ) AND wordpress_posts.post_type = 'post' AND (wordpress_posts.post_status = 'publish' OR wordpress_posts.post_status = 'private') GROUP BY wordpress_posts.ID ORDER BY wordpress_posts.post_date DESC LIMIT 0, 20wordpress_posts  INNER JOIN wordpress_term_relationships ON (wordpress_posts.ID = wordpress_term_relationships.object_id) WHERE 1=1  AND ( wordpress_term_relationships.term_taxonomy_id IN (200,210,220,230,240,250,260,270,280,290) ) AND wordpress_posts.post_type = 'post' AND (wordpress_posts.post_status = 'publish' OR wordpress_posts.post_status = 'private')
    PHP:
    Do you maybe know what's wrong?
     
    ZanM, Feb 18, 2013 IP
  6. innozemec

    innozemec Active Member

    Messages:
    84
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    68
    #6
    i saw one issue.. 20wordpress_posts

    put a space after 20
     
    innozemec, Feb 18, 2013 IP
  7. ZanM

    ZanM Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #7
    Thanks, but where is this code created, so I can pust space in between?

    Thank you!
     
    ZanM, Feb 18, 2013 IP