Jump to content

code diplayin user added even if they are not


runnerjp

Recommended Posts

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

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
}
?>

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<?
		}
?>

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??

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
}
?>

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

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<?
		}
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.