runnerjp Posted June 6, 2008 Share Posted June 6, 2008 on my main profile page im creating a user added section... basicly if a user is either the user whos profile it is or the user is allready i friend it does not shopw the adduser code... else if they are not then show add user code... <?php session_start(); include '../settings.php'; $get_username_value = get_username($id); $query = mysql_query("SELECT * FROM `friends` WHERE `username` = '$get_username_value' AND `friendname` = 'RUNNINGP'"); $check = mysql_fetch_array($query); if($check) { ?>SHOW ADD USERS<? }else{ ?>user allready added<? } ?> so i did this but it always retuns userallready added be it the user is in the db or is not Quote Link to comment https://forums.phpfreaks.com/topic/109033-code-diplayin-user-added-even-if-they-are-not/ Share on other sites More sharing options...
jonsjava Posted June 6, 2008 Share Posted June 6, 2008 I wouldn't write it the way you did, but going off what you did: <?php session_start(); include '../settings.php'; $get_username_value = get_username($id); $query = mysql_query("SELECT * FROM `friends` WHERE `username` = '$get_username_value' AND `friendname` = 'RUNNINGP'"); $result = mysql_query($query); $check = mysql_fetch_array($result); if($check) { ?>SHOW ADD USERS<?php }else{ ?>user allready added<?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/109033-code-diplayin-user-added-even-if-they-are-not/#findComment-559373 Share on other sites More sharing options...
aseaofflames Posted June 6, 2008 Share Posted June 6, 2008 try instead of if($check), if(mysql_num_rows($query)>0) <?php session_start(); include '../settings.php'; $get_username_value = get_username($id); $query = mysql_query("SELECT * FROM `friends` WHERE `username` = '$get_username_value' AND `friendname` = 'RUNNINGP'"); $check = mysql_fetch_array($query); if(mysql_num_rows($query)>0) { ?>SHOW ADD USERS<? }else{ ?>user already added<? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/109033-code-diplayin-user-added-even-if-they-are-not/#findComment-559376 Share on other sites More sharing options...
runnerjp Posted June 6, 2008 Author Share Posted June 6, 2008 I wouldn't write it the way you did, but going off what you did: <?php session_start(); include '../settings.php'; $get_username_value = get_username($id); $query = mysql_query("SELECT * FROM `friends` WHERE `username` = '$get_username_value' AND `friendname` = 'RUNNINGP'"); $result = mysql_query($query); $check = mysql_fetch_array($result); if($check) { ?>SHOW ADD USERS<?php }else{ ?>user allready added<?php } ?> how would you write it?? Quote Link to comment https://forums.phpfreaks.com/topic/109033-code-diplayin-user-added-even-if-they-are-not/#findComment-559393 Share on other sites More sharing options...
runnerjp Posted June 6, 2008 Author Share Posted June 6, 2008 oh end both codes still display user allready added even thought the uer is not added as its made up lol Quote Link to comment https://forums.phpfreaks.com/topic/109033-code-diplayin-user-added-even-if-they-are-not/#findComment-559395 Share on other sites More sharing options...
jonsjava Posted June 6, 2008 Share Posted June 6, 2008 try this one: <?php session_start(); include '../settings.php'; $get_username_value = get_username($id); $query = mysql_query("SELECT * FROM `friends` WHERE `username` = '$get_username_value' AND `friendname` = 'RUNNINGP'"); $result = mysql_query($query); $check = mysql_fetch_assoc($result); if($check['username'] == $get_username_value) { ?>SHOW ADD USERS<?php }else{ ?>user allready added<?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/109033-code-diplayin-user-added-even-if-they-are-not/#findComment-559407 Share on other sites More sharing options...
runnerjp Posted June 6, 2008 Author Share Posted June 6, 2008 hey ok that does oposit and just shows SHOW ADD USERS is it because your doing this if($check['username'] == $get_username_value) { as its getitng my logged in name...as what im trying to do is get list of users who IM friends WITH and if im not there firend yet show ADD USER Quote Link to comment https://forums.phpfreaks.com/topic/109033-code-diplayin-user-added-even-if-they-are-not/#findComment-559412 Share on other sites More sharing options...
jonsjava Posted June 6, 2008 Share Posted June 6, 2008 Ok, then just modify what value it's pulling, to suit your needs. Sry, I don't know your db table well enough to do much more. Quote Link to comment https://forums.phpfreaks.com/topic/109033-code-diplayin-user-added-even-if-they-are-not/#findComment-559416 Share on other sites More sharing options...
runnerjp Posted June 6, 2008 Author Share Posted June 6, 2008 this is my firend table friendname username Admin Princessemma Princessemma Admin very simple Quote Link to comment https://forums.phpfreaks.com/topic/109033-code-diplayin-user-added-even-if-they-are-not/#findComment-559421 Share on other sites More sharing options...
aseaofflames Posted June 7, 2008 Share Posted June 7, 2008 this is my firend table friendname username Admin Princessemma Princessemma Admin very simple so does this mean there is no RUNNINGP in your friend table? that could be why you always get the same result (it returns no rows) maybe you should use <?php session_start(); include '../settings.php'; $get_username_value = get_username($id); $query = mysql_query("SELECT * FROM `friends` WHERE `username` = '$get_username_value'"); $check = mysql_fetch_array($query); if(mysql_num_rows($query)==0) { ?>SHOW ADD USERS<? }else{ ?>user already added<? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/109033-code-diplayin-user-added-even-if-they-are-not/#findComment-559638 Share on other sites More sharing options...
runnerjp Posted June 7, 2008 Author Share Posted June 7, 2008 ahh yes that wrokd... but how would i also stop users from adding themselfs ?? Quote Link to comment https://forums.phpfreaks.com/topic/109033-code-diplayin-user-added-even-if-they-are-not/#findComment-559713 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.