Domanda

alt text

esempio se ho

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

questione

Come faccio ad avere tutta la feeds.description dalla società che la mia azienda (esempio qui è cid = 1)?

Heres mia semplice SQL DOP per ottenere solo la mia.

    $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

forse qualcosa di simile? (Fail)

    $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

o semplice get feeds.description da ogni follow.following (cid = 1,2,3, ecc) da me. (CID = 1) o se Twitter Ottieni tutti i miei amici di stato (amici che seguo)

modifica *

alcuni buoni ragazzi di IRC mysql detto di utilizzo si unisce. ma Ho appena non capisco. ciò che ottengo è questo

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

poi

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

qualcuno mi può dare un esempio per unisce in questo problema?

È stato utile?

Soluzione

Quindi, supponendo che la domanda è "Come faccio ad avere tutta la feeds.description dalla società che la mia azienda sta seguendo?" si desidera partecipare utilizzando il tasto seguente:

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;

Questo dovrebbe elencare tutte le società che il vostro:. Cid (1) sta seguendo

EDIT:. Feed dovrebbe includere i feed + mia azienda alimenta la mia azienda sta seguendo

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top