0

I am trying to develop a small photo cataloging and storage system in PHP / MySQL. Currently my database is structured as follows:

CREATE TABLE `photos` (
  `picid` varchar(36) NOT NULL,
  `uploaded` varchar(10) NOT NULL,
  `picdesc` text NOT NULL,
  `views` bigint(20) NOT NULL,
  `albumid` varchar(36) NOT NULL COMMENT 'fkey albums',
  `uploadedby` varchar(50) NOT NULL COMMENT 'fkey users',
  `exif` longtext NOT NULL,
  `album_protected` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`picid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

The picid field is a GUID used as the primary key.

I need help with creating an SQL query that will return the record previous to a passed in picid and the record next from it too. I think I will need to use two queries, but perhaps someone can tell me otherwise. The records are ordered by uploaded which is a UNIX TIMESTAMP value.

Hope you can help! Please tell me if you require more info!

4

1 回答 1

0

给它一个 auto_increment 整数字段作为主键,并将 picid 更改为唯一。作为唯一的,它将被索引并且仍然可以用作查找。但是如果你想要你的行中的序列,你需要一个 auto_increment 字段,并且这些字段必须是 MySql 中的主键。

 CREATE TABLE `photos` (
 `rowid` int auto_increment primary key,
 `picid` varchar(36) NOT NULL UNIQUE,
 `uploaded` varchar(10) NOT NULL,
 `picdesc` text NOT NULL,
 `views` bigint(20) NOT NULL,
 `albumid` varchar(36) NOT NULL COMMENT 'fkey albums',
 `uploadedby` varchar(50) NOT NULL COMMENT 'fkey users',
 `exif` longtext NOT NULL,
 `album_protected` tinyint(1) NOT NULL default '0'
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
于 2013-08-28T21:04:05.513 回答