» »

SQL problem

SQL problem

Trubadur ::

Evo sql stavk:

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:8)
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

Trubadur ::

naka ne dela.Javla mi da ni novic čeprov so:)
Berite Thomasa!

Trubadur ::

	$sql = 'SELECT * 
			FROM news
			INNER JOIN images
			ON news.id=images.newsID';
Berite Thomasa!

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 :)

Trubadur ::

ja kle sm pozabu where;)
Berite Thomasa!

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 ;)

Trubadur ::

Ne sej deluje;)

$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!
..::} Life Is Like A Box Of Ammo {::..


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

mysql vnos

Oddelek: Izdelava spletišč
51061 (1026) asgard2.0
»

portal ostal, baza sla

Oddelek: Izdelava spletišč
61047 (932) bombacina
»

anketa z vec moznostmi

Oddelek: Izdelava spletišč
12972 (851) Packač
»

mySQL(+php) auto_increment field v tabeli.. Kako...?

Oddelek: Izdelava spletišč
6671 (603) Zvonko
»

enostaven vnos v bazo MySQL

Oddelek: Izdelava spletišč
101219 (1122) Borci

Več podobnih tem