Jump to content

Recommended Posts

Is it possible to pass 2 values in the name="" property of the Form Input??

 

Here is my current code...

<input id='Friend" . $friendID . "_1' name='friendStatus["
	. $friendID . "]' type='radio' value='1' "
	. ((isset($friendStatus[$friendID]) && $friendStatus[$friendID] == '1') ? "checked='checked'" : "") .
" />
<label for='Friend" . $friendID . "_1'>Remain Friends</label>

 

When my "Manage Friendships" Form is submitted, instead of just passing $friendID back to my script, I need to find some easy way to pass $requestorID and $requesteeID back to my script so I can update the appropriate Friend record.

 

Is that possible?

 

(This sounds like a job for an Array, but once again I am finding out that I am a weenie when it comes to working with arrays!!!)  :-[

 

Thanks,

 

 

Debbie

 

Link to comment
https://forums.phpfreaks.com/topic/263681-passing-2-values-in-input-name-field/
Share on other sites

No. You could combine two things into one "value" but that's generally a bad idea.

 

I see two possibilities:

1. Friendships go both directions: if A is a friend of B then B is automatically a friend of A. In which case there should only be one record which one side being the current user and the other side being the other user (be that requestor/requestee or vice versa). And the query looks like

WHERE (requestor = current user AND requestee = other user) OR (requestor = other user AND requestee = current user)

2. Friendships are unidirectional: if A is a friend of B that does not mean B is a friend of A. In which case the requestor is always the current user and the requestee is always the other person.

 

Either way you only need to keep the other user's ID in the form.

No. You could combine two things into one "value" but that's generally a bad idea.

 

I see two possibilities:

1. Friendships go both directions: if A is a friend of B then B is automatically a friend of A. In which case there should only be one record which one side being the current user and the other side being the other user (be that requestor/requestee or vice versa). And the query looks like

WHERE (requestor = current user AND requestee = other user) OR (requestor = other user AND requestee = current user)

2. Friendships are unidirectional: if A is a friend of B that does not mean B is a friend of A. In which case the requestor is always the current user and the requestee is always the other person.

 

Either way you only need to keep the other user's ID in the form.

 

Let me explain the design I chose.  (And let me stress that it is set in concrete at this point!)

 

I have a "friend" table that looks like this...

requestor	requestee	requestor_approved	requestee_approved
----------	----------	-------------------	-------------------
19		1		1			1
2		19		1			1
19		3		1			1

 

I am #19

 

In the above sample data...

 

"DoubleDee" requested friendship with "Username1" who accepted.

 

"Username2" requested friendship with "DoubleDee" who accepted.

 

"DoubleDee" requested friendship with "Username3" who accepted.

 

 

The script I am working "manage_friendships.php" displays all Friends for the currently logged in Member (e.g. 19=DoubleDee).  Specifically, the Friend's Username, Photo and 2 radio buttons ("Remain Friends", "End Friendship") are displayed in a row, with the next Friend below in the following row, and so on.

 

I was trying to use the code I used for "manage_requests.php" which managed all Incoming Friend-Requests.

 

The problem that I discovered, however, is that with Incoming Friend-Requests I only need the "RequestorID" because I am obviously always the "Requestee" when it comes to people sending me Friend-Requests.

 

Rewind...

 

To update a "Friendship" - see table above - I need to know if the Friend was the Requestor or the Requestee because I need to either update the "Requestor_Approved" field from 1=Accepted to 2=Declined OR I need to either update the "Requestee_Approved" field from 1=Accepted to 2=Declined?!

 

So re-using my "Manage Friend-Requests" code won't work without some modification...

 

All of this seems like a real PITA, but I stand behind my Database design!

 

So, as a recap, when I look in my DoubleDee account I would see...

Requenix	_X__ Remain Friends	__ End Friendship

 

...and when I click "Update Friendships", I need to send over that RequestorID=19, RequesteeID=1234 and Status=1

 

Make sense?

 

Hopefully there is a way to do what I want without a billion lines of code OR a Database Rework - which isn't an option since I have thousands of lines of code written to match my one table, one record per Friendship model...

 

What do you think?

 

Thanks,

 

 

Debbie

 

 

So no on a billion lines of code. How about just two?

UPDATE friend SET requestor_approved = 1 WHERE requestor = current user AND requestee = other user
UPDATE friend SET requestee_approved = 1 WHERE requestor = other user AND requestee = current user

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.