Home  >  Article  >  Backend Development  >  PHP logic is dead! Deletion guidelines for comments

PHP logic is dead! Deletion guidelines for comments

WBOY
WBOYOriginal
2016-09-06 08:57:111275browse

<code><? if($row['id']==$_SESSION['id']){?>
                            <? if($com['id']==$_SESSION['id']){?>
                            
                            <button id="remove_<? echo $com['comment_id'];?>">
                            刪除
                            </button>

                            <? }?>
                        <? }?>
</code>

The above is my program code
comment_id is the ID automatically generated after leaving a message
com['id'] is the ID left by the user after leaving a message
SESSION['id'] is the user's own ID (you will get it when you log in )
row['id'] is the ID automatically generated by the user who published the article
The user himself can leave a message in the "own article"
Other users can also leave a message in the "own article"

So I got stuck

If it is written like this

<code><? if($com['id']==$_SESSION['id']){?>
                            <div style="position:absolute; right:0; top:0;" id="show_remove_<? echo $row['timeline_id'];?>">
                            
                            <button id="remove_<? echo $com['comment_id'];?>" class="n2">
                            <i style="color:#ccc; font-size:15px;" class="material-icons">delete_forever</i>
                            </button>
                            
                            </div>
                        <? }?>
</code>

If you write like this, when the user (or others) reads your own article, the user's own message will be displayed as "Delete"

<code><? if($row['id']==$_SESSION['id']){?>
                            
                            <div style="position:absolute; right:0; top:0;" id="show_remove_<? echo $row['timeline_id'];?>">
                            
                            <button id="remove_<? echo $com['comment_id'];?>" class="n2">
                            <i style="color:#ccc; font-size:15px;" class="material-icons">delete_forever</i>
                            </button>
                            
                            </div>
                            
                        <? }?>
</code>

If you write like this, when you read your own article, all comments will be displayed as "Delete"
But when others read your article, nothing will be displayed

The purpose I want is to **if the article is posted by myself
so the comments below can be displayed as "Delete" whether it is yourself or someone else
But when others read your article, their own comments will be displayed as "Delete"* *

Logic is dead...Help me handsome guys and beauties!

Reply content:

<code><? if($row['id']==$_SESSION['id']){?>
                            <? if($com['id']==$_SESSION['id']){?>
                            
                            <button id="remove_<? echo $com['comment_id'];?>">
                            刪除
                            </button>

                            <? }?>
                        <? }?>
</code>

The above is my program code
comment_id is the ID automatically generated after leaving a message
com['id'] is the ID left by the user after leaving a message
SESSION['id'] is the user's own ID (you will get it when you log in )
row['id'] is the ID automatically generated by the user who published the article
The user himself can leave a message in the "own article"
Other users can also leave a message in the "own article"

So I got stuck

If you write it like this

<code><? if($com['id']==$_SESSION['id']){?>
                            <div style="position:absolute; right:0; top:0;" id="show_remove_<? echo $row['timeline_id'];?>">
                            
                            <button id="remove_<? echo $com['comment_id'];?>" class="n2">
                            <i style="color:#ccc; font-size:15px;" class="material-icons">delete_forever</i>
                            </button>
                            
                            </div>
                        <? }?>
</code>

If you write like this, when the user (or others) reads your own article, the user's own message will be displayed as "Delete"

<code><? if($row['id']==$_SESSION['id']){?>
                            
                            <div style="position:absolute; right:0; top:0;" id="show_remove_<? echo $row['timeline_id'];?>">
                            
                            <button id="remove_<? echo $com['comment_id'];?>" class="n2">
                            <i style="color:#ccc; font-size:15px;" class="material-icons">delete_forever</i>
                            </button>
                            
                            </div>
                            
                        <? }?>
</code>

If you write like this, when you read your own article, all comments will be displayed as "Delete"
But when others read your article, nothing will be displayed

The purpose I want is to **if the article is posted by myself
so the comments below can be displayed as "Delete" whether it is yourself or someone else
But when others read your article, their own comments will be displayed as "Delete"* *

Logic is dead...Help me handsome guys and beauties!

Can’t you just add a relationship of ||?

<code><? if ($com['id'] == $_SESSION['id'] || $row['id'] == $_SESSION['id']) { ?>
    <div style="position:absolute; right:0; top:0;" id="show_remove_<? echo $row['timeline_id'];?>">
        <button id="remove_<? echo $com['comment_id'];?>" class="n2">
            <i style="color:#ccc; font-size:15px;" class="material-icons">delete_forever</i>
        </button>
    </div>
<? }?></code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:sql traversal resultsNext article:sql traversal results