Forum » Programiranje » SQL problem
SQL problem
Trubadur ::
Evo sql stavk:
Napaka:
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 'WHERE news.status = 1' at line 4
Mam pa mysql 4.0.18
SELECT news.*, images.thumb AS src_thumb, images.image AS image FROM news INNER JOIN images WHERE news.id = images.newsID WHERE news.status = 1
Napaka:
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 'WHERE news.status = 1' at line 4
Mam pa mysql 4.0.18
Berite Thomasa!
- spremenil: kopernik ()
Trubadur ::
Aja strukture tabel:
CREATE TABLE `images` (
`picID` int(11) NOT NULL auto_increment,
`newsID` int(11) NOT NULL default '0',
`src_thumb` varchar(250) NOT NULL default '',
`src_image` varchar(250) NOT NULL default '',
PRIMARY KEY (`picID`)
) TYPE=MyISAM COMMENT='images' AUTO_INCREMENT=2 ;
CREATE TABLE `news` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(50) NOT NULL default '',
`date` date NOT NULL default '0000-00-00',
`day` varchar(10) NOT NULL default '',
`time` time NOT NULL default '00:00:00',
`txt` text NOT NULL,
`status` tinyint(4) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='news' AUTO_INCREMENT=5 ;
In zdj hočm dobit vn:
Iz slik->thumb,image
Iz novic vse.
Ampak ni nujno da pr slikah obstaja thumb in image oz. je prazno. Ni nujno da uporabnik uploada sliko.hope u understand
CREATE TABLE `images` (
`picID` int(11) NOT NULL auto_increment,
`newsID` int(11) NOT NULL default '0',
`src_thumb` varchar(250) NOT NULL default '',
`src_image` varchar(250) NOT NULL default '',
PRIMARY KEY (`picID`)
) TYPE=MyISAM COMMENT='images' AUTO_INCREMENT=2 ;
CREATE TABLE `news` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(50) NOT NULL default '',
`date` date NOT NULL default '0000-00-00',
`day` varchar(10) NOT NULL default '',
`time` time NOT NULL default '00:00:00',
`txt` text NOT NULL,
`status` tinyint(4) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='news' AUTO_INCREMENT=5 ;
In zdj hočm dobit vn:
Iz slik->thumb,image
Iz novic vse.
Ampak ni nujno da pr slikah obstaja thumb in image oz. je prazno. Ni nujno da uporabnik uploada sliko.hope u understand
Berite Thomasa!
BigWhale ::
SELECT news.*, images.thumb AS src_thumb, images.image AS image
FROM news
INNER JOIN images WHERE news.id = images.newsID
WHERE news.status = 1
SELECT ... FROM news, images WHERE news.id=images.newsID AND news.status = 1
FROM news
INNER JOIN images WHERE news.id = images.newsID
WHERE news.status = 1
SELECT ... FROM news, images WHERE news.id=images.newsID AND news.status = 1
BigWhale ::
Ampak tole ti vrne drugacen rezultat, kot si ga ti hotel v prvem queriju... ;)
Sicer je bil prvi query narobe napisan ampak zdaj v tem drugem, ne pocnes istih stvari kot prej :)
Sicer je bil prvi query narobe napisan ampak zdaj v tem drugem, ne pocnes istih stvari kot prej :)
Pirrat ::
Namesto WHERE news.id = images.newsID WHERE news.status = 1
poskusi z WHERE news.id = images.newsID AND news.status = 1
mogoce bo delovalo ;)
poskusi z WHERE news.id = images.newsID AND news.status = 1
mogoce bo delovalo ;)
Trubadur ::
Ne sej deluje
Zamenju sm inner join z levim
$sql = 'SELECT * FROM news LEFT JOIN images ON news.id=images.newsID WHERE news.status = ' . $status . ' ORDER BY news.id DESC LIMIT 5';
Zamenju sm inner join z levim
Berite Thomasa!
Bossek ::
tudi prvi bi delal če bi napisal namesto
INNER JOIN images WHERE news.id = images.newsID
INNER JOIN images ON news.id = images.newsID
ON ne WHERE!
INNER JOIN images WHERE news.id = images.newsID
INNER JOIN images ON news.id = images.newsID
ON ne WHERE!
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | mysql vnosOddelek: Izdelava spletišč | 1533 (1498) | asgard2.0 |
» | portal ostal, baza slaOddelek: Izdelava spletišč | 1813 (1698) | bombacina |
» | anketa z vec moznostmiOddelek: Izdelava spletišč | 1592 (1471) | Packač |
» | mySQL(+php) auto_increment field v tabeli.. Kako...?Oddelek: Izdelava spletišč | 1093 (1025) | Zzzzzzz |
» | MySQL združevanje tabel..Oddelek: Programiranje | 1699 (1514) | Nemenej |