0

我在查询 2 表专辑和图像中需要一些帮助

我需要从数据库中选择一些字段,它们之间有一个user_id

询问:

  $album_query = mysql_query("SELECT `albums`.`album_id`, `albums`.`timestamp`, `albums`.`name`, LEFT(`albums`.`description`, 50) as `description`, COUNT(`images`.`image_id`) as `image_count`
     FROM `albums`
     LEFT JOIN `images`
     ON `albums`.`album_id` = `images`.`album_id`
     WHERE `albums`.`user_id` = '**here it must take the session created before**'
     GROUP BY `albums`.`album_id`") or die(mysql_error());

这是代码块:

<?php 

ob_start();
if(!isset($_SESSION))
{
session_start();
}

require_once('include/connect.php'); 



if(isset($_GET['user_id']))
{
    $id=$_GET['user_id'];


}
elseif(isset($_SESSION['user_id']))
{
    $id= $_SESSION['user_id'];
}

else
{
     require_once('index.php');

    exit();

}

 //function to ge the data for the album
 function album_data($album_id)
 {

 }
 //check if the album  belong to the particular user
 function album_check($album_id)
 {
 }

 //get thelist of albums 
 function get_albums()
 {

     $albums = array();
     $album_query = mysql_query("SELECT `albums`.`album_id`, `albums`.`timestamp`, `albums`.`name`, LEFT(`albums`.`description`, 50) as `description`, COUNT(`images`.`image_id`) as `image_count`
     FROM `albums`
     LEFT JOIN `images`
     ON `albums`.`album_id` = `images`.`album_id`
     WHERE `albums`.`user_id` = ''
     GROUP BY `albums`.`album_id`") or die(mysql_error());

     while($albums_row = mysql_fetch_array($album_query))
     {
         $albums[] = array(
                'id' =>$albums_row['album_id'], 
                'timestamp'=>$albums_row['timestamp'],
                'name'=>$albums_row['name'],
                'description'=>$albums_row['description'],
                'count'=>$albums_row['image_count']
         );

     }
     return $albums;
 }


       function create_album($album_name, $album_description)
 {
     $album_name= mysql_real_escape_string(htmlentities($album_name));
     $album_description= mysql_real_escape_string(htmlentities($album_description));

     mysql_query("INSERT INTO albums VALUES('', '" .$_SESSION['user_id']. "', UNIX_TIMESTAMP(), '$album_name','$album_description')");

     mkdir('uploads/'.mysql_insert_id(), 0744);
     mkdir('uploads/thumbs/'.mysql_insert_id(), 0744);


 }

?>


*elseif(isset($_SESSION['user_id']))
    {
        $id= $_SESSION['user_id'];
    }*

这是错误,因为系统不允许我分配 album.user_id = $id 并且数据库字段存储 0

我不知道我是否以一种可以理解的方式解释了我的问题

谁能帮我 ???

4

1 回答 1

0

你应该改变这一行

 WHERE `albums`.`user_id` = ''

像这样:

WHERE `albums`.`user_id` = '".$id."'
于 2013-08-22T07:51:11.437 回答