Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-28-2012, 08:44 PM   PM User | #1
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
how to get this to show for each user

hey guys, im having a bit of trouble with this, ill explain it a bit more in detail below:

basically, i have this piece of code, i want it to show whats after it to each user involved (in every case it will only be 2 people)

PHP Code:
if ((($fetch_escrow->invited == $fetch->username) && ($fetch_escrow->invitedlevel == 0)) || (($fetch_escrow->invited == $fetch->username) && ($fetch_escrow->invitedlevel == 0))) { 
now 1 user is in the db as $fetch_escrow->invited and one is in as $fetch_escrow->username.

the idea is that if (($fetch_escrow->invited == $fetch->username) && ($fetch_escrow->invitedlevel == 0)) it will show, but if (($fetch_escrow->invited == $fetch->username) && ($fetch_escrow->invitedlevel == 1)) it wont, and exactly the same for the $fetch_escrow->username but im having problems having it show for one, and not for the other.

any help would be great as i dont want to have to copy the script and write it twice if theirs and easier way around it.

thanks.

Dan
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags

Last edited by Dan13071992; 11-29-2012 at 10:31 PM..
Dan13071992 is offline   Reply With Quote
Old 11-28-2012, 09:30 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
if ((($fetch_escrow->invited == $fetch->username) && ($fetch_escrow->invitedlevel == 0)) || (($fetch_escrow->invited == $fetch->username) && ($fetch_escrow->invitedlevel == 0))) {

So this always has to be true:
$fetch_escrow->invited == $fetch->username

And this can be either a zero (0) or one (1):
$fetch_escrow->invitedlevel == 0
$fetch_escrow->invitedlevel == 1

Is that the correct logic?

Create a logic table for me so I can visualize it.


EDIT: maybe this?

if (($fetch_escrow->invited == $fetch->username) && ($fetch_escrow->invitedlevel == 0 || $fetch_escrow->invitedlevel == 1)) {



.
mlseim is offline   Reply With Quote
Old 11-28-2012, 09:43 PM   PM User | #3
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
sorry for not explaining it correctly. its a bit mind bogling to explain lol.

basically, if user=fetchescrow->username and username level == 0 dislay everything after the {

but then in the same thing but for the invited user, and invited level == 0 then display.

but if either has a 1 instead of a 0 do not display it to the person with the 1

does that make sense?
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 11-29-2012, 12:51 AM   PM User | #4
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Quote:
username level
You have a reference to "invitedlevel", but no reference or variables shown for "usernamelevel".

if ((($fetch_escrow->invited == $fetch->username) && ($fetch_escrow->invitedlevel == 0)) || (($fetch_escrow->invited == $fetch->username) && ($fetch_escrow->invitedlevel == 0))) {

That is 3 variables isn't it?

I'm guessing you have something called "usernamelevel" ??



.

Last edited by mlseim; 11-29-2012 at 02:00 AM..
mlseim is offline   Reply With Quote
Old 11-29-2012, 09:55 AM   PM User | #5
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
im sorry, i must have wrote it out incorrectly on here.. yes you are right, there is invitedlevel and userlevel both being drawn by the $fetch_escrow->

if ((($fetch_escrow->invited == $fetch->username) && ($fetch_escrow->invitedlevel == 0)) || (($fetch_escrow->username== $fetch->username) && ($fetch_escrow->usernamelevel == 0))) {

so for each one it should display, only if its a 0, but if one changes to a 1 then it will not display for them, but will still display for the other user that has 0
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 11-29-2012, 01:11 PM   PM User | #6
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Let's try expanding it out first, to make it easier to see what is happening ...

PHP Code:

if($fetch_escrow->invited == $fetch->username){
   if(
$fetch_escrow->invitedlevel ){
   echo 
"Display for the invited";
   }
   if(
$fetch_escrow->usernamelevel ){
   echo 
"Display for the user";
   }


Try that and see if it works.



.
mlseim is offline   Reply With Quote
Old 11-29-2012, 03:23 PM   PM User | #7
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
that works for the invited user only, not the username user
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 11-29-2012, 04:19 PM   PM User | #8
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Run it various ways and show me the results for it each time ...

PHP Code:

// we need to see what the variables really are ...
echo "Invited is: ".$fetch_escrow->invited."<br />";
echo 
"Invited_level is: ".$fetch_escrow->invitedlevel."<br />";
echo 
"Username is: ".$fetch_escrow->username."<br />";
echo 
"Username_level is: ".$fetch_escrow->usernamelevel."<br />";

if(
$fetch_escrow->invited == $fetch->username){ 
   if(
$fetch_escrow->invitedlevel ){ 
   echo 
"Display for the invited"
   } 
   if(
$fetch_escrow->usernamelevel ){ 
   echo 
"Display for the user"
   } 

You're going to see what is wrong by looking at the values.


.
mlseim is offline   Reply With Quote
Old 11-29-2012, 04:23 PM   PM User | #9
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
Invited is: testaccount
Invited_level is: 0
Username is: DOS1392
Username_level is: 0

thats what i get.

which is correct,

now i want it to display "anything here" for each user "testacount" and "dos1392" as long as their own level is 0, but if theres is 1 and the other level for the other user is 0 still display to the other user, just not to the user with the 1
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 11-29-2012, 06:43 PM   PM User | #10
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
But look here: $fetch_escrow->invited == $fetch->username

You are requiring the invited name and username to be equal (the same).
Nothing will ever happen if they are different.

Let's look at your example:
Invited is: testaccount
Invited_level is: 0
Username is: DOS1392
Username_level is: 0

So this will always be false no matter if the level is 0,1,2, or 1000
The two items in red are NOT EQUAL.
According to you, that is a requirement.



.
mlseim is offline   Reply With Quote
Old 11-29-2012, 07:13 PM   PM User | #11
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
sorry, let me try to explain, this is an escrow system:

one user invites another user, the inviter is set as username in the escrow table, the invited is set as invited in the escrow table, $fetch->username is the session (user logged in) now each user needs to finalize their items in the escrow, to do this they are both set to 0 from the beginning. if username (inviter) clicks the finalize button, it updates "usernamelevel" to "1", but invited is still set to 0 so it should still show the finalize button.

this is where im stuck, instead of re writing everything out for each user, i wanted to find a work around to display to either of the users as long as their user or invited level == "0"

i hope that has explained it a bit more, if not im more than willing to provide a picture.
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 11-29-2012, 07:51 PM   PM User | #12
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Tell me if my theory of operation is at all close to what you're doing.

To start out, let's say there are already 147 other users logged-in.

I sit down at my computer...

I am 'mlseim'
I log in and a SESSION is set for me (I'm logged-in).

You are 'dan1307'
You log in and a SESSION is set for you (You're logged-in).

I want to invite you, so four variables are set:
$fetch_escrow->username is now 'mlseim'
$fetch_escrow->usernamelevel is now set to 0
$fetch_escrow->invited is now 'dan1307'
$fetch_escrow->invitedlevel is now set to 0

You mentioned those are stored in a db (database?), like a temporary MySQL table?

Do you (dan1307) and I (mlseim) see the same database variables in real time?

How are you storing these in a db?
How do you know that I invited you?
And how do I know that you accepted my invitation?



.
mlseim is offline   Reply With Quote
Old 11-29-2012, 08:17 PM   PM User | #13
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
your bang on

yes it is stored in a mysql database, that is temporary as long as the escrow is open.

invites are sent out and the invited user must accept the invite.

then comes the other part ive already coded that works fine, placing items such as cars, money ect ect into the escrow system, that works fine and is all coded.

then once each user has put in what they want, they each INDIVIDUALLY press the finalize button (this is the part im having trouble with) as i want that button to show up for each user if they are set to 0, but if they are set to 1 i dont want it to show.

my problem is, how can i make it show for one user, and not the other, whilst only writting that finalize button out once, instead of twice for each person?


but going back to how you worked it out, you was bang on, right down to the T
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 11-29-2012, 08:47 PM   PM User | #14
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
As long as I am logged-in and I invited you, there must be a SESSION variable someplace that my PHP script knows which database table to query.

You are logged-in on your computer, and you also have a SESSION variable that tells your PHP script which database table to query.

We are both querying the same temporary table, isn't that correct?

We are both running (or using) the same PHP script, and we both have a SESSION variable that tell us which temporary table to use.

Whenever either of us queries that db table, the PHP script has to determine whether we are the "inviter" or the "invitee". You set a SESSION to know what the table name is, but no other information.

So, I would guess you do this ...

Whenever the page displays, the PHP does these steps:
1) It already knows my login SESSION.
2) It queries the database for those 4 things.
3) It determines if I'm the "inviter" or the "invitee".
4) If I'm the "inviter", it looks to see if my "level" is 0 (for userlevel).
5) If so, it shows the button.
6) If I'm the "invitee", it looks to see if my "level" is 0 (for invited_level).
7) If so, it shows the button.
8) If I had clicked my finalize button, it would update the appropriate column for me.
9) It goes back to step 1.

So you have to do 2 "if" statements (step 4-5) and (step 6-7)

PHP Code:

// I need to know the user's login SESSION

$loginsession $_SESSION['whatever the user login variable name is'];

if(
$fetch_escrow->invited == $loginsession){  
   if(
$fetch_escrow->invitedlevel ){  
   echo 
"Display Finalize Button";  
   }
}
if(
$fetch_escrow->username == $loginsession){  
   if(
$fetch_escrow->usernamelevel ){  
   echo 
"Display Finalize Button";
   }



.
mlseim is offline   Reply With Quote
Old 11-29-2012, 08:58 PM   PM User | #15
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
this part is bang on:

PHP Code:

if($fetch_escrow->invited == $loginsession){  
   if(
$fetch_escrow->invitedlevel ){  
   echo 
"Display Finalize Button";  
   }
}
if(
$fetch_escrow->username == $loginsession){  
   if(
$fetch_escrow->usernamelevel ){  
   echo 
"Display Finalize Button";
   }

but my question to it is, how can i write it so that i only have to have "Display Finalize Button" in there once and it would work for both users?
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:14 PM.


Advertisement
Log in to turn off these ads.