Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2010
    Posts
    3

    Unanswered: 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?

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    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

  3. #3
    Join Date
    Apr 2010
    Posts
    3
    touche!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •