Jump to content

reading values into a list


dvespa

Recommended Posts

Hi All,

 

Hoping someone can assist.

 

I have a two list on names which I retrieve from a database.

 

List 1:  5 Names  <A drop down list for user to select>

 

List 2:  5 Names  <A drop down list for user to select>

 

<Names are the same in both lists>

 

What I'd like to achieve is once the user selects the name is List 1 than this name is removed from List 2. Hence we only retrieve 4 names.

 

Does anyone have any samples of how I can perform the following.

 

Cheers for reading  ;D

 

David.

Link to comment
https://forums.phpfreaks.com/topic/194700-reading-values-into-a-list/
Share on other sites

Well...hrmn. 

 

What you're describing sounds a bit odd.  BUT, there are multiple ways you could do this.

 

No matter what, if you want this to happen when they SELECT an item in the list (not when they say, post a form) you are going to have to write some javascript.

 

Explain a bit more hwat you're trying to do, or post some code...because right now it's not making a whole lot of sense :)

 

If you're posting the form tho, you could simply run

 

DELETE from user_table_2 WHERE name = "$username";

 

but that sounds awful too...

 

If you are doing any sort of user management, you want to reference your users as ID numbers not as names.  that way say you had two "steve" users...that query above would nuke both of them from the database. 

 

 

Hi  Just to clarify - what I am coding is a voting system.

 

After a sports game I'm asking people to vote for their best 5 players.

 

5 Votes  < DROP DOWN LIST OF 20 NAMES>

4 Votes  < DROP DOWN LIST OF 20 NAMES>

3 Votes  < DROP DOWN LIST OF 20 NAMES>

2 Votes  < DROP DOWN LIST OF 20 NAMES>

1 Votes  < DROP DOWN LIST OF 20 NAMES>

 

Now the list of names are currently coming from the same table.

 

When someone selects "NAME 1" for 5 Votes then the list presented for 4,3,2,1 votes must eliminate this name ( they can not select the same name for 4 votes). And then when someone select a name for 4 votes then this name must not appear for 3,2,1 votes etc etc

 

Hope this helps.

 

Thx all

 

David

OHHHH ok :)

 

Yeah, what you want to do is done via javascript.

 

(That way they can't vote for the same player twice?)

 

Here is some really quick dirty javascript that you can copy/paste to see what I'm talking about

 

<script type = 'text/javascript' src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type='text/javascript'>

$(document).ready(function(){



$('select').bind('change',function(){

	var value = $(this).val();

	$(this).siblings('select').children('.' + value).hide();		

});

$('#reset').bind('click',function(){
	$('select').children().show();

});


});

</script>

<button id="reset">Reset values!</button>
<select>
<option class="user1">user1</option>
<option class="user2">user2</option>
<option class="user3">user3</option>
<option class="user4">user4</option>
<option class="user5">user5</option>
</select>


<select>
<option class="user1">user1</option>
<option class="user2">user2</option>
<option class="user3">user3</option>
<option class="user4">user4</option>
<option class="user5">user5</option>
</select>

<select>
<option class="user1">user1</option>
<option class="user2">user2</option>
<option class="user3">user3</option>
<option class="user4">user4</option>
<option class="user5">user5</option>
</select>

<select>
<option class="user1">user1</option>
<option class="user2">user2</option>
<option class="user3">user3</option>
<option class="user4">user4</option>
<option class="user5">user5</option>
</select>

 

Edit:  Added a button so you can "reset values" (basically it shows all the options again).  That way as options became unavailable, and if they goofed up they can go back to an initial state.  Hope this helps!

Glad it helped :)

 

With jQuery it's important to understand how those selectors work.  The reason it works vertically is it's gathering all the sibling elements in the Dom (in this case the siblings are all select elements)

 

if you wanted to acheive the same thing with say....th select nested in a div you would want to go

 

$("div select").bind("click...

 

Then

 

$(this).siblings("div select")....

 

That should get you started, if you're still having troubles shoot me a PM and well work it out...since it's a JavaScript solution don't want to post too much on the php board ;)

 

good luck!

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.