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

    Major Problems with including retrieving data from two tables.

    Greetings All,
    I am currently writing an application that has two tables.

    Tables = CONTENT and THEME_IMAGE

    CONTENT FIELDS = id, title, description, theme_id
    THEME_IMAGE FIELDS = theme_id, title, filename

    I have already written a script to output information from both tables. However, I am now working on a script to UPDATE the database from the web browser.

    The CONTENT table is used to store information about an article. Each article has a theme image, but many articles can use the same theme image, hence the need for separate THEME_IMAGE table.
    Now, when I go to edit the CONTENT article, there is a <select> field which should display ALL the contents from THEME_IMAGE table. This is so that when a user is editing the CONTENT article, they can select a new THEME IMAGE if one hasn't been selected already.

    Now, the problem I am getting is I don't know how to interlink two tables (CONTENT + IMAGE_THEME) so that the user can see the IMAGE_THEME Image Title in the <select> <option> tags, and when they choose it, the "id" is written to the CONTENT theme_id table so that it can be referenced later.

    Also, if there is a theme image already choosen, it should display that.

          <td>Theme Image:</td>
          <td><select name='Theme_Image'>
          <? if($onecontent->Theme_Image!="") { ?>
                <option SELECTED value='<?php echo($Theme_Image); ?>'> <?php echo($Theme_Image); ?> </option>
    	<? } else {?>   
                <option value=''> No Theme_Image </option>
    	<? }?>   
                    $sql = "select * from theme_image order by Theme_Title";
                    $images = mysql_query($sql, $db);
                    while($oneimage = mysql_fetch_object($images))
                        echo ("<option value='$oneimage->File'>$oneimage->Theme_Title</option>");

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Thanked 637 Times in 625 Posts
    I believe all you need to do is use the theme_id for the value of each option. When the form is submitted the theme_id the user selected will be available via $_POST (or $_GET if you are using method="get") and you can then run an UPDATE query to plop the selected theme_id into the appropriate row in your content table.
    PHP Code:
    echo "<option value=\"$oneimage->theme_id\">$oneimage->Theme_Title</option>"


    Posting Permissions

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