php - Hiding/displaying button based on conditions and issues with basic queries -
i in mid development of social networking site. trying hide , display buttons based on conditions set coming across difficulties before that. @ moment, mind cannot process how specify code.
i have add favourites
visible on pages besides profile page of user logged in. let's assume logged in freddy, , go alice's profile page, button visible, , actions specified button work, data sent database. however, trying specify once user in logged in users favourites, add favourites
button replaced remove favourites
.
i unable first of all, specify user can favourite user once, @ moment, when add favourites
clicked on profile, database update many rows, when freddy should allowed favourite alice once.
this have tried @ moment allow user favourited once:
<?php // code process favourite request if (isset($_post['addfriend'])) { $fav_request = $_post['addfriend']; $favourited_who = $user; // u variable $favourited_by = $username; // logged in user /* * need check user logged in, hasnt got $user in there favs */ // step 1: favourites of logged in user... $q = mysqli_query ($connect, "select * favourites"); while ($r_query = mysqli_fetch_array($q)) { $db_fav_who = $r_query['favourited_who']; $db_fav_by = $r_query['favourited_by']; // step 2: check whether profile page user viewing, isnt in there favourites... // check: see if $user isn't in there favourites. if ($db_fav_by == $username){ // check see users favourites checking // if user exists in logged in users favourites, display remove favourites button. if ($db_fav_who == $user){ echo "<div class='edit_profile'> <input type='submit' class='btn btn-info' name='remfriend' value='remove favourites'> </div"; } } }// while loop closed if ($user != $username) { // check: see user isnt favouriting themself. $favourite_user = mysqli_query($connect, "insert favourites values ('', '$favourited_who', '$favourited_by')"); echo "done "; } } // if isset closed ?>
at moment, there 2 buttons visible when going onto anyone's (besides own) profile page:
<div class="edit-profile"> <?php if ($user == $username){ // dont display buttons }else { ?> <form action="" method="post"> <?php echo " <input type='submit' class='btn btn-info' name='sendmsg' value='send message'/> <input type='submit' class='btn btn-info' name='addfriend' value='add favourites'> </form>"; } ?> </div>
note: $user
variable u variable in url. $username
session variable logged in user.
how can add favourites
button visible if he/she not in logged in users variable? , if are, how can remove favourites
button visible instead of add favourites
button?
Comments
Post a Comment