Nasıl yorumlarına cevap yapabilirim?

6 Cevap php

Ben cevap cevap sonra, yorum var burada reddit, ardından yorumuna cevap gibi bir şey oluşturmak istiyorum.

Veritabanı yapısı ne tür onlar kadar kullanırım:

1. they keep track of all the comments to a posting
2. a reply to a comment
3. a reply to a reply

Ben doğru olan bütün sadece bir ilanı ve benzeri buna ilişkin yorumların bir demet ..

POSTING TABLE
posting_id | title | author

COMMENTS TABLE
comment_id | posting_id | comment

REPLIES TABLE
????

How do I relate the comments to the replies? What type of css do they use to give replies that indented space?

EDIT: Thanks for the answers! Now my only question how do I indent the replies? Such as..

you like food
     yes I love italian
        Yes i do like it too
     chinese is best

6 Cevap

Eğer kullanıcı yanıtlarken comment (ya da cevap) ve kimliği ile doldurmak nerede parent_comment_id belirterek yorumlarınızı tabloya başka bir sütun ekleyebilirsiniz. Yorum yazı (bir yorumuna değil cevap) doğrudan bir cevap olduğunu durumda bu sütun null olacaktır.

Cevaplarda içinde cevap göstermek için, alt yanıtlar üreten tutmak için yinelemeli çağrı yapmak gerekecek.

Gibi bir şey

function get_comments($comment_id) {
    print '<div class="comment_body">';

    // print comment body or something?

    if (comment_has_reply($comment_id)) {
        foreach(comment_comments($comment_id) as $comment) {
            get_comments($comment->id);
        }
    }

    print '</div>';
}

Ancak yorumlarınızı girintili yazmak için, kullanım css.

<style type="text/css">
.comment_body {
    margin-left:10px;
}
</style>

Böylece bu şekilde alt mesaj içermekte ebeveyn daha girintili ve onların subs daha girintili, ve.

Yorumlarınızı masada "reply_to" ya da böyle başka bir alan eklemek, ve orada cevapta olduğu yorumun id saklayın.

Bunu gibi yorumlar tablo genel yapabilir:

COMMENTS TABLE
comment_id | posting_type | posting_id | comment

posting_type diskriminatör çeşit, örneğin bir dize 'POST' veya 'YORUM', ya da daha fazla verimlilik için bir tam sayıdır (1 = POST, 2 = YORUM, vb.)

edit: kuşkusuz bu daha karmaşık ama bir şey üzerinde yorum değil, sadece mesaj ve diğer yorumlar için aynı açıklama tablosunu kullanabileceğiniz anlamına gelir.

Yanıtların masa gerekmez. Diğerleri zaten doğru bir şekilde belirttiği gibi, özyineleme bir RDBMS ile gitmek için yoludur. Her zaman özyineleme ile uğraşmak zorunda kalmamak için, bir NoSQL stil DBMS kullanarak düşünebiliriz.

Ben bir çapraz başvuru tablosu yaparak bu yapardı.

Örnek:

Table: Posts

Columns: pstkey | userid | postMessage | etc...

pstkey is the key for the post body. userid is the person who created the post. postMessage is the actual post entry.

Table: Comments

Columns: comkey | pstkey | userid | commentMessage | etc...

comkey is the key for the comment made. referenced to the post using the pstkey. userid is the person who made the comment. and then commentMessage is the text body of the actual comment.

Table: xref_postComm

Columns: xrefkey | pstkey | comkey | comkey2 |

Now for the fun part. ALL posts go into post table. ALL comments go into comment table. The relationships are all defined in the Cross Reference Table.

Benim programlama tüm bu şekilde yapmak. Ben dünyalardan birinin emekli ve bana bir kaç numara öğretilen veritabanı mühendis bests ile çalışmak için ayrıcalıklı oldu.

How to use the Cross Reference table:

xrefkey | pstkey | comkey | comkey2
All that you look for is the population of a given field.

xref (Auto Incremented)
pstkey (Contains the pstkey for the post)
comkey (Contains the comkey for the comment post)
comkey2 (Contains the comkey for the comment post)
        (but only populate comkey2 if comkey already has a value)
and of course you populate comkey2 with the key of the comment.

SEE, no reason for a 3rd tabel!

With this method you can add as many relationships as you want. 
Now or in the future!

comkey2 bir cevapta için cevap. Nerede hangi Bu tek satır .... yazının anahtarı, yorumun anahtarını ve cevap yorumuna cevap anahtarı içerir. Tüm xref nüfus tarafından yapılır.

EXAMPLE:
PAGES.... Page table

POSTS
 pstkey | pageid | user| Post
-------------------------------------
|   1   |    1   |  45 | Went to the store the....|
|   2   |    2   |  18 | Saw an apple on tv.....

COMMENTS
 comkey | pstkey | user  | Comment
-----------------------------------------------
|   1   |    1   |   9   | Wanted to say thanks...
|   2   |    1   |   7   | Cool I like tha.....
|   3   |    2   |   3   | Great seeing ya....
|   4   |    2   |   6   | Had a great....
|   5   |    2   |   2   | Don't sweat it man...

xref_PostCom
xrefkey | pageid | pstkey | comkey | comkey2 |
----------------------------------------------
|   1   |   1    |   1    |  NULL  |   NULL  | Post1 on Page1
|   2   |   1    |   1    |   1    |   NULL  | Comment1 under Post1
|   3   |   1    |   1    |   2    |   NULL  | Comment2 under Post1
|   4   |   2    |   2    |  NULL  |   NULL  | Post2 on Page2
|   5   |   2    |   2    |   3    |   NULL  | Comment3 under Post2 on Page2
|   6   |   2    |   2    |   4    |   NULL  | Comment4 under Post2 on Page2 (a second Comment)
|   7   |   2    |   2    |   4    |    5    | Explained below....
Comment key 5 is matched with comment key 4....under post2 on Page 2

Katılmak hakkında bir şey biliyorsanız, dış / iç işiniz çok daha kolay olur, veri dizileri bu ilişkileri kullanarak elde SELECT en oluşturarak katılmak, doğru katılmak, katılmak bıraktı.

Ben mühendisin çağrısını tanımlanan ilişkilerin bu temelde "veri haritası" inanıyorum. Hüner, bu ilişkileri kullanarak erişmek nasıl şimdi. Bu ilk başta zor yolunmuş, ama ben bildiklerimi biliyorum, ben bunu başka bir şekilde yapmayı reddediyorum.

Ne sonunda olur siz diyor 1. Senaryoyu yazarken sonuna kadar olduğunu, tamam, ahh yapmak gitmek her şeyi ve geri gel. Sen sayfa 1 sorar 1 işlev çağrısı ile sona erecek. Bu sayfadır1 ile döner, 1, comment1 & 2 & 3 ve 1 dizi yanıta cevap gönderebilir. çıktı yankı ve aferin.

UPDATE FOR COMMENT I said the same exact thing the first time it was shown to me. As a matter of fact it really was making me mad that the database programmer was forcing me to do it this way. But now I get it. The advantages are so many.

Avantaj 1) 1 sorgu 1 atış tüm dışarı çekmek için yazılmış olabilir.

2) çoklu sorgularda Cevapları sayfayı yazdırırken bir döngü içinde bir döngü sayfayı görüntülemek edebileceği bir yapıda diziler doldurabilirsiniz.

3) bu hiç aklınıza gelebilecek olası tasarım değişikliğini destekleyen kullanan yazılım yükseltme. Kusursuz genişleme.

Bunu öğretti bana adam Sears ve JCPenny veritabanlarını yeniden tasarlanmış işe silah oldu. Onlar çünkü yinelenen kayıtları sorunları aynı evde gidiyor 9 kitap var ne zaman geri.

Çapraz referans tabloları tasarımı konularda bir sürü engeller.

Bu teoriye kalp bir sütun veri içeren ama aynı zamanda bir doğru veya yanlış beyanı olarak hizmet değil sadece, olduğunu. Bu kadar kendini o yer kazandırır. Eğer bir arama varken neden 20 tablolar mı arıyorsunuz? 1 endeksli çapraz başvuru tablosu size ihtiyacınız yok ne gerek ne içeriği, diğer 20 tablolar hakkında bilmeniz gereken her şeyi söyleyebilir ve hatta tüm diğer tabloyu açmak gerekiyor.

IN SHORT: 1 Cross reference containing nothing but INT(2/11) that tells you everything thing you need to know before you ever open another table, not only contains flawless expandability but lighting speed results. Not to mention little possibility of duplicate records. To you and me duplicate records may not be an issue. But to Sears with 4 billion records at $11 a book, mistakes add up.