HAi everybody,

I need help in flowing code

i want to people not equal to friend means show addas friend buuton otherwise not show button

this code show button more times

what is the problem in my logic

anybody plz help me.

This is my friends get query.

$query=$db->prepare("SELECT p.friend_id , p.layer_id
                                        from layer l, people p
                                        where l.personal_id = :personal_id
                                        and l.id = p.layer_id
                                        GROUP BY p.friend_id    


        "); 
        $query->execute(array('personal_id' => $this->personal->getId()));

            $this->friends = $query->fetchAll();






<?php 
                    foreach($people as $p): ?>

                    <div id="vv-ppl-profile" class="friends">
                        <h3><?php echo $p["full_name"] ?></h3>
                        <a href="viewprofile?personal_id=<?php echo $p['id'] ?>" > <div class="vv-ppl-profile-thumb" style="background-image:url('<?php echo url_for('@image_display_new?from='.$p['primary_album_id'].'&type=personal&pic_id='.$p['profile_picture_id'], true); ?>') " >
                     </div></a>

                        <?php foreach($friends as $fr):?>
                            <?php if(($fr['id'])!=($p['id'])):?>
                            <div class="vv-ppl-cta vv-ppl-add">
                                <input type="hidden" value="<?php echo $p['id'] ?>"  />
                                    <p>Add Friend</p>
                                </div>
                            <?php endif;?>

                        <?php endforeach;?>
                        <?php endforeach;?>
Member Avatar for LastMitch

i want to people not equal to friend means show addas friend buuton otherwise not show button

What is the issue? You need to be more specific. Is there any errors when you run the code?

You have 2 <?php foreach;?> loops so was there an error?

If there's no error what data appears.

If no error means i want to show addas friend btn
i corrected my template but still show btn more than twice.

<?php endforeach;?>
</div>
<?php endforeach;?>
Member Avatar for LastMitch

If no error means i want to show addas friend btn
i corrected my template but still show btn more than twice

Instead of this:

<?php foreach($people as $p): ?>
<div id="vv-ppl-profile" class="friends">
<h3><?php echo $p["full_name"] ?></h3>
<a href="viewprofile?personal_id=<?php echo $p['id'] ?>" ><div class="vv-ppl-profile-thumb" style="background-image:url('<?php echo url_for('@image_display_new?from='.$p['primary_album_id'].'&type=personal&pic_id='.$p['profile_picture_id'], true); ?>') " >
</div></a>
<?php foreach($friends as $fr):?>
<?php if(($fr['id'])!=($p['id'])):?>
<div class="vv-ppl-cta vv-ppl-add">
<input type="hidden" value="<?php echo $p['id'] ?>" />
<p>Add Friend</p>
</div>
<?php endif;?>
<?php endforeach;?>
<?php endforeach;?>

Try this (I took out the second loop):

<?php foreach($people as $p): ?>
<div id="vv-ppl-profile" class="friends">
<h3><?php echo $p["full_name"] ?></h3>
<a href="viewprofile?personal_id=<?php echo $p['id'] ?>" > <div class="vv-ppl-profile-thumb" style="background-image:url('<?php echo url_for('@image_display_new?from='.$p['primary_album_id'].'&type=personal&pic_id='.$p['profile_picture_id'], true); ?>') " >
</div></a>
<?php endforeach;?>

<?php foreach($friends as $fr):?>
<?php if(($fr['id'])!=($p['id'])):?>
<div class="vv-ppl-cta vv-ppl-add">
<input type="hidden" value="<?php echo $p['id'] ?>" />
<p>Add Friend</p>
</div>
<?php endif;?>
<?php endforeach;?>

What error did you get or what data appear?

i did not getin error,button show more times.

i want to everypeoplename and button
this button show in this condition based
<?php if(($fr['id'])!=($p['id'])):?>

for exp
Name
adas friend

name2
addasfriend

plz help me.

Member Avatar for LastMitch

i want to everypeoplename and button
this button show in this condition based

Try this (Did you write this code with this kind of format):

<?php foreach($people as $p): ?>
<div id="vv-ppl-profile" class="friends">
<h3><?php echo $p["full_name"] ?></h3>
<a href="viewprofile?personal_id=<?php echo $p['id'] ?>" ><div class="vv-ppl-profile-thumb" style="background-image:url('<?php echo url_for('@image_display_new?from='.$p['primary_album_id'].'&type=personal&pic_id='.$p['profile_picture_id'], true); ?>') " >
</div></a>
<?php foreach($friends as $fr):?>
<?php endforeach;?>
<?php endforeach;?>

<?php if(($fr['id'])!=($p['id'])):?>
<div class="vv-ppl-cta vv-ppl-add">
<input type="hidden" value="<?php echo $p['id'] ?>" />
<p>Add Friend</p>
</div>
<?php endif;?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.