Link to home
Start Free TrialLog in
Avatar of John Account
John Account

asked on

PHP query returned value problem...

Hi again Experts.... Julia here...

I have the following query on a page, which returns a chat room name.  According to that name, I assign a value to another variable to say if that chat room is either public or private.  Now, this works for certain rooms and not for others and it 's very unstable.  Sometimes it returns the right thing, sometimes it doesn't, so I'm baffled.  I tried everything, single = , double ==, if/else statements, if/elseif/else statements... Nothing works, so I come to you...

here is the code on the page.  Keep in mind that I'm just a little amateure programmer, so this might be all very confusing cause it's not necessarilly as neet as it should be ;)

//------------------------------------------------

$IP;


$Sql = "Select avail, Login, Member from PM where IpAddress = '$IP'";
$res = mysql_query($Sql);
$row = mysql_fetch_assoc($res);
$result= $row['avail'];
$result2= $row['Login'];
$result3= $row['Member'];

$Sql4 = "Select picture from pictures where member = '$result3'";
$res4 = mysql_query($Sql4);
$row4 = mysql_fetch_assoc($res4);
$result4= $row4['picture'];

$Sql5 = "Select Broadcasting from PM where IpAddress = '$IP'";
$res5 = mysql_query($Sql5);
$row5 = mysql_fetch_assoc($res5);
$result5= $row5['Broadcasting'];

$Sql7 = "Select info2, info4 from profile where ID = '$result3'";
$res7 = mysql_query($Sql7);
$row7 = mysql_fetch_assoc($res7);
$result7= $row7['info2'];
$result8= $row7['info4'];

$Sql8 = "Select room from chat_users where name = '$result2'";
$res8 = mysql_query($Sql8);
$row8 = mysql_fetch_assoc($res8);
$room = $row8['room'];


echo $result;
echo ',';
echo $result2;
echo ',';
echo $result3;
echo ',';
if ($result4) {
echo 'http://www.mysite.com/pictures/'; echo $result4;
echo ',';

} else {

echo 'http://www.mysite.com/pictures/nopic.gif';
echo ',';
}

if ($result5 == 1) {
echo 'Broadcasting,';
}
else {
echo 'Not Broadcasting,';
}

if ($room == 'The Lounge' || $room == 'The Penthouse' || $room == ' The Bar' || $room == 'Friends' || $room == 'Couples' || $room == 'Swingers' || $room == 'Married' || $room == 'Single Parents') {
echo 'Public';
}
else {
echo 'Private';
}

echo ',';
echo $result7;
echo ',';
echo $result8;

?>



----------------------------------------------------------------------

So, what is going on here?  Why is it that when I'm in my room "The Bar" it still says i'm in a private room when, as far as I can see, it should say PUBLIC, no?  I also tried it like this...

if ($room = 'The Lounge' || $room = 'The Penthouse' || $room = ' The Bar' || $room = 'Friends' || $room = 'Couples' || $room = 'Swingers' || $room = 'Married' || $room = 'Single Parents') {
echo 'Public';
}
else {
echo 'Private';
}

in which case it says that i'm in a public room even when I'm in a private one... ARGHHHH... Help!
ASKER CERTIFIED SOLUTION
Avatar of ASCII_Man
ASCII_Man

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ASCII_Man
ASCII_Man

>I don't see where this $room variable is been assigned anywhere in the code

Oh, I see it now :)
None the less, perhaps the value in the database isn't clean.
simple suggestion:

change the variables
$result1
$result2
$result3
$result4
$result5

to variablenames with a meaning, that way your code will be more easy to read
Get the idea?
the name $result2 doesn't say a thing to me, but if it would be $username I would expect a username to be in there, wich helps in understanding the code.
Avatar of John Account

ASKER

Thank YOu SOOOO much ASCII man...

THAT --->

 $room = trim($room);
if ($room == 'The Lounge' || $room == 'The Penthouse' || $room == ' The Bar' || $room == 'Friends' || $room == 'Couples' || $room == 'Swingers' || $room == 'Married' || $room == 'Single Parents') {
echo 'Public';
}

Did the trick just fine.  Eveything now is peachy!  Thanks again for your help, you saved me once again!

Julia