Wordpress数据库 - 您的SQL语法中有错误

时间:2013-02-10 15:35:17

标签: database wordpress syntax

我有以下代码:

<?php

        $exists_photos = $wpdb->get_results("SELECT * FROM $dsp_galleries_photos galleries, $dsp_user_albums_table albums WHERE galleries.album_id=albums.album_id AND galleries.status_id=1 AND galleries.album_id IN ($ids1) ORDER BY RAND() LIMIT 6");

         $i=0;

         foreach ($exists_photos as $user_photos) { 

            $photo_id=$user_photos->gal_photo_id;

            $album_id1=$user_photos->album_id;

            $file_name=$user_photos->image_name;

            $private=$user_photos->private_album;

            $image_path="/wp-content/uploads/dsp_media/user_photos/user_".$member_id."/album_".$album_id1."/".$file_name;

            if(($i%3)==0){

            ?>

它返回以下错误:

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(*) FROM wp_dsp_galleries_photos WHERE status_id=1 AND album_id IN () made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/ArtSee/page.php'), the_content, apply_filters('the_content'), call_user_func_array, do_shortcode, preg_replace_callback, do_shortcode_tag, call_user_func, wp_include_file, include('/plugins/dsp/profile_header.php'), include('/plugins/dsp/member_dsp_header.php'), include('/plugins/dsp/headers/view_profile_header.php'), include('/plugins/dsp/view_profile_setup.php')

建议将不胜感激。感谢

2 个答案:

答案 0 :(得分:0)

你错过了一个内部价值()

SELECT COUNT(*) FROM wp_dsp_galleries_photos WHERE status_id=1 AND album_id IN () 

声明: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 ')'表示失败的意义。我引用了第二个)

... album_id IN () ...

在任何情况下,您的代码都不会显示此部分。

答案 1 :(得分:-1)

SELECT * FROM $dsp_galleries_photos galleries, $dsp_user_albums_table albums 

应该是

SELECT * FROM dsp_galleries_photos galleries, dsp_user_albums_table albums 

在表名之前没有$ - 您还应该考虑是否确实需要选择*但这不会影响查询的语法