If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Stored array into dropdown

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-02-10, 11:33
Tim Schutz Tim Schutz is offline
Registered User
 
Join Date: Apr 2010
Posts: 3
Stored array into dropdown

I have array data that was previously stored like so:

Code:
$allTeams=array('SF','CHI','CIN');
$userTeam=implode(',',$allTeams);
$query = "INSERT INTO users VALUES ('$userTeam')";
Now, I would like to populate a dropdown list with this array data. Here is what I have tried:

Code:
<select name="teamList" id="teamList">
<?php

include 'dbcon.php';

mysql_select_db($database, $conn);
	$query  = "SELECT userTeam FROM users WHERE fullName='Tim Schutz'";
	$result = mysql_query($query);
	while($row = mysql_fetch_assoc($result))
	{ 
	echo '<option value="' . $row['fullName'] . '">' . $row['userTeam'] . '</option>';
	}	

?>
</select>
The dropdown gets populated, but as one long string as a single item. I tried exploding the data, but nothing shows. Can anyone point me in the right direction?
Reply With Quote
  #2 (permalink)  
Old 04-02-10, 11:56
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Quote:
Originally Posted by Tim Schutz
Can anyone point me in the right direction?
Do I understand you correctly ...
You've stored the value 'SF','CHI','CIN' into a table and now you're confused when you select the data from this table and it returns the value 'SF','CHI','CIN'.
Can I suggest you store the values separately and that you perhaps read up on normalisation
__________________
Mike
Reply With Quote
  #3 (permalink)  
Old 04-02-10, 12:05
Tim Schutz Tim Schutz is offline
Registered User
 
Join Date: Apr 2010
Posts: 3
touche!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On