Alıntı:
Alıntı
28
●10.833
SELECT fc.id, fc.title, fp.id AS fpid, fp.title AS fptitle
FROM forum_content AS fc, forum_polls AS fp
WHERE fc.username = '{$user->username}' AND fp.username = '{$user->username}'Tablo yapısı:`id` int(11) unsigned NOT NULL auto_increment, `content` text NOT NULL, `title` varchar(40) NOT NULL, `username` varchar(20) NOT NULL
$sql = "SELECT c.id,c.title as 'contentTitle',p.id,p.title as 'pollsTitle' FROM forum_content as c INNER JOIN forum_polls as p ON c.id=p.id WHERE c.username='{$user->username}'";
$query = mysql_query($sql) or die (mysql_error());
$assoc = mysql_fetch_assoc($query);
echo $assoc['contentTitle'];
echo $assoc['pollsTitle'];gibi yapmalısın.
SELECT fc.id, fc.title AS fc_title, fc.user, fp.title AS fp_title FROM forum_content fc LEFT JOIN forum_polls fp ON fc.user = fp.user
SELECT c.id as 'contentID', c.title as 'contentTitle',p.id as 'pollsID',p.title as 'pollsTitle' FROM forum_content as c INNER JOIN forum_polls as p ON c.username=p.username WHERE c.username='{$user->username}'Lâkin EzSQL sorgunun dökümünü şöyle gösteriyor: ezSQL (v2.03) Variable Dump..
Array
(
[0] => Array
(
[contentID] => 7
[contentTitle] => Tanışalım
[pollsID] => 1
[pollsTitle] => Yeni Sitemiz
)
[1] => Array
(
[contentID] => 169
[contentTitle] => Video istek
[pollsID] => 1
[pollsTitle] => Yeni Sitemiz
)
[2] => Array
(
[contentID] => 170
[contentTitle] => Program İstek
[pollsID] => 1
[pollsTitle] => Yeni Sitemiz
)
[3] => Array
(
[contentID] => 171
[contentTitle] => Oyun İstek
[pollsID] => 1
[pollsTitle] => Yeni Sitemiz
)
)
Type: Array
Last Query [17]: SELECT c.id as 'contentID', c.title as 'contentTitle',p.id as 'pollsID',p.title as 'pollsTitle' FROM forum_content as c INNER JOIN forum_polls as p ON c.username=p.username WHERE c.username='Administrator'
Last Function Call: $db->query("SELECT c.id as 'contentID', c.title as 'contentTitle',p.id as 'pollsID',p.title as 'pollsTitle' FROM forum_content as c INNER JOIN forum_polls as p ON c.username=p.username WHERE c.username='Administrator'")
Last Rows Returned: 4Yâni forum_content alanında 4, forum_polls alanında ise 1 tane içerik var. Bu durumda forum_content'i listelerken forum_polls alanındaki içeriği hep tekrarlıyor. Bunu nasıl önleyebiliriz?ezSQL (v2.03) Variable Dump..
Array
(
[0] => Array
(
[id] => 7
[fc_title] => Tanışalım
[username] => Administrator
[fp_title] => Yeni Sitemiz
)
[1] => Array
(
[id] => 169
[fc_title] => Video istek
[username] => Administrator
[fp_title] => Yeni Sitemiz
)
[2] => Array
(
[id] => 170
[fc_title] => Program İstek
[username] => Administrator
[fp_title] => Yeni Sitemiz
)
[3] => Array
(
[id] => 171
[fc_title] => Oyun İstek
[username] => Administrator
[fp_title] => Yeni Sitemiz
)
)
Type: Array
Last Query [17]: SELECT fc.id, fc.title AS fc_title, fc.username, fp.title AS fp_title
FROM forum_content fc
LEFT JOIN forum_polls fp ON fc.username = fp.username WHERE fc.username='Administrator'
Last Function Call: $db->query("SELECT fc.id, fc.title AS fc_title, fc.username, fp.title AS fp_title
FROM forum_content fc
LEFT JOIN forum_polls fp ON fc.username = fp.username WHERE fc.username='Administrator'")
Last Rows Returned: 4 SELECT p.id as 'pollsID',c.id as 'contentID', c.title as 'contentTitle',p.title as 'pollsTitle' FROM forum_content as c INNER JOIN forum_polls as p ON c.username=p.username WHERE c.username='{$user->username}' GROUP BY p.id,c.idOlmazsa şunu dene.SELECT content.*,polls.* FROM (c.id as 'contentID', c.title as 'contentTitle',c.username FROM forum_content as c WHERE c.username='{$user->username}') as content INNER JOIN (SELECT p.id as 'pollsID',p.title as 'pollsTitle',p.username FROM forum_polls as p WHERE p.username='{$user->username}') as polls ON content.username=polls.username Array
(
[0] => Array
(
[pollsID] => 1
[contentID] => 7
[contentTitle] => Tanışalım
[pollsTitle] => Yeni Sitemiz
)
[1] => Array
(
[pollsID] => 1
[contentID] => 169
[contentTitle] => Video istek
[pollsTitle] => Yeni Sitemiz
)
[2] => Array
(
[pollsID] => 1
[contentID] => 170
[contentTitle] => Program İstek
[pollsTitle] => Yeni Sitemiz
)
[3] => Array
(
[pollsID] => 1
[contentID] => 171
[contentTitle] => Oyun İstek
[pollsTitle] => Yeni Sitemiz
)
)
Type: Array
Last Query [17]: SELECT p.id as 'pollsID',c.id as 'contentID', c.title as 'contentTitle',p.title as 'pollsTitle' FROM forum_content as c INNER JOIN forum_polls as p ON c.username=p.username WHERE c.username='Administrator' GROUP BY p.id,c.id
Last Function Call: $db->query("SELECT p.id as 'pollsID',c.id as 'contentID', c.title as 'contentTitle',p.title as 'pollsTitle' FROM forum_content as c INNER JOIN forum_polls as p ON c.username=p.username WHERE c.username='Administrator' GROUP BY p.id,c.id")
Last Rows Returned: 4İkinci sorgunun hatası:Warning: 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 ''contentID', c.title as 'contentTitle',c.username FROM forum_content as c WHERE '
SELECT content.*,polls.* FROM (SELECT c.id as 'contentID', c.title as 'contentTitle',c.username FROM forum_content as c WHERE c.username='{$user->username}') as content INNER JOIN (SELECT p.id as 'pollsID',p.title as 'pollsTitle',p.username FROM forum_polls as p WHERE p.username='{$user->username}') as polls ON content.username=polls.username---SELECT c.*,(SELECT p.id as 'pollsID',p.title as 'pollsTitle',p.username FROM forum_polls as p WHERE p.username='{$user->username}') as polls FROM forum_content WHERE c.username='{$user->username}')