Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    36
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question PHP MySql Select Box Help

    I have a form that selects data from database table 1 and then on submission of the form inserts them into table 2. I need help with seperating the variables before insertion in the table 2.

    Here is my code:

    PHP Code:
    $query4 "SELECT artist_id,artist_name FROM artists ORDER BY artist_name";      
    $result4 mysql_query($query4) or die(mysql_error());

    echo 
    "<select name='artist'>";

    while(
    $row=mysql_fetch_array($result4))
      {
       echo 
    "<option value='"$row['artist_id'] . $row['artist_name'] ."'>"$row['artist_name'] ."</option>";
      }
    echo 
    "</select> 
    As you can see I select artist_name and artist_id from seperate columns in table 1. The results are:

    PHP Code:
    <option value='13Adam Fielding'>Adam Fielding</option
    I need the artist_id and artist_name get passed into table 2 in seperate columns just as they were selected from the table 1.

    How do I do this ??

    Thanks.

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    Duplicating data in multiple tables is NOT a good idea.

    What does table 2 represent (how is it used later)?

  • #3
    New Coder
    Join Date
    Feb 2012
    Posts
    36
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Table 1 contains all artist information. Website, bio, facebook page, graphic, etc.
    I use this info for individual artist pages on my site.

    Table 2 contains info on which artists are heard on a particular show. show id, track number, artist id, artist name, and song.

    The only two columns they have in common are artist_id and artist_name.

    I link to individual artist pages from the page that shows what artists play on a certain show. I need the name and artist id for building the links.
    Last edited by ansonb; 03-13-2012 at 07:31 AM. Reason: forgot a word

  • #4
    New Coder
    Join Date
    Feb 2012
    Posts
    36
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Please Help


  •  

    Posting Permissions

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