我有以下代碼:WordPress的數據庫 - 你的SQL語法有錯誤
<?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')
建議將不勝感激。由於
這些是PHP變量。如果你看看這個錯誤,你可以看到它們在SQL執行之前被轉換爲適當的表名 - 即,'wp_dsp_galleries_photos'。這不是錯誤的地方。 – 2013-02-10 15:49:16
我總是被教導你需要在表名中轉義$符號,所以它必須是SELECT * FROM'$ dsp_galleries_photos'畫廊或者是海報錯別字 - 我的錯誤 – bhttoan 2013-02-10 15:53:55
也是代碼發佈並不包含錯誤中顯示的代碼,這是我跳到表名 – bhttoan 2013-02-10 15:54:46