Frage

alt text

Beispiel, wenn ich

follow table
company one ( cid = 1 ) following two ( cid = 2 )
company one ( cid = 1 ) following three( cid = 3 )

feeds table
company one ( cid = 1 ) type 'product' description 'hello ive updated a product';
company two ( cid = 2 ) type 'product' description 'hello ive updated a product im from company 2';
company three ( cid = 3 ) type 'shoutout' description 'hello ive i got a shoutout im company 3';
company one ( cid = 1 ) type 'product' description 'hello ive updated my second product';

Frage

Wie bekomme ich alle feeds.description von der Firma, dass meine Firma (Beispiel hier cid = 1 ist)?

here meine einfache gU SQL nur meine zu erhalten.

    $data['feeds']['cid'] = 1;

    return $this->db->fetchAll("SELECT feeds.type, feeds.$type, feeds.cid, feeds.time, companies.name FROM feeds, companies WHERE 
    feeds.cid = :cid AND companies.cid = :cid ORDER BY feeds.fid DESC LIMIT 0, 5", $data['feeds']);

this will display
hello ive updated a product
hello ive updated my second product

vielleicht so etwas wie das? (Gescheitert)

    $data['feeds']['cid'] = 1,2,3;

    return $this->db->fetchAll("SELECT feeds.type, feeds.$type, feeds.cid, feeds.time, companies.name FROM feeds, companies WHERE 
    feeds.cid = :cid AND companies.cid = :cid ORDER BY feeds.fid DESC LIMIT 0, 5", $data['feeds']);

this should be displaying like
hello ive updated a product
hello ive updated a product im from company 2
hello ive i got a shoutout im company 3
hello ive updated my second product

oder einfacher get feeds.description von jedem follow.following (cid = 1,2,3, usw.) von mir. (Cid = 1) oder wenn twitter get all meine Freunde Status (Freunde, dass ich folgen)

edit *

einige gute Jungs bei irc mysql sagte Einsatz verbindet. aber bekomme ich nur nicht, dass es. was ich bekommen, ist dies

fetch all the follow.following from cid = me ( example cid = 1 )

dann

SELECT * FROM feeds WHERE feeds.cid = IN (2,3,cid that im following ( see follow.following )) 

jemand kann mir ein Beispiel für in diesem Problem tritt?

War es hilfreich?

Lösung

Also, vorausgesetzt, dass die Frage „Wie bekomme ich alle feeds.description von der Firma, dass meine Firma finden?“ Sie wollen mit dem folgenden Schlüssel verbinden:

select 
companies.name, 
feeds.type, 
feeds.description 
from follow 
inner join feeds on (follow.following = feeds.cid or follow.cid = feeds.cid)
inner join companies on (feeds.cid = companies.cid)
where follow.cid = :cid
order by feeds.fid desc 
limit 5;

Dies sollte alle Unternehmen Liste, dass Ihr. Cid (1) folgt

EDIT:. Feeds soll meine Firma Feeds enthält + Feeds meiner Firma folgt

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top