Skip to main content
Known Participant
July 8, 2010
Question

A recordset-related question

  • July 8, 2010
  • 1 reply
  • 511 views

I have a database set up with three tables, foreign keys etc set up correctly. I need to set up a form which will upload a review of an organisation to one of these tables, but because I want to have reviews published for each organisation on a separate page, I need to have the person posting the review select the organisation from a drop-down menu. This menu will be populated from a different table.

This is probably an obvious newbie question, but I've not worked with foreign keys before and can't get my head round how it will work. I don't have a problem with the upload form part, that's something I've done before, but I've never tried to pull in data from another table and link it in this way - is it going to work if I set up a recordset from my "organisations" table to dynamically generate the list of organisations, then set up the form that uploads the new data to the "reviews" table?

I can't decide whether it's more simple than I think it is, or more complex, but I'm sure I'm not the first person to try and do something like this, so if anyone's had experience of this and can point me in the right direction, I'd really appreciate it. Thanks in advance.

This topic has been closed for replies.

1 reply

BenPleysier
Community Expert
Community Expert
July 9, 2010

You need to supply the label and the value to the select list, the label being the name that you want shown and the value being the value of the foreign key.

I hope this helps.

Ben

PS  If we were privy to the code, we may be able to supply you  with a more specific answer.

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
jeffmgAuthor
Known Participant
July 9, 2010

Ben - thanks for responding. At the moment I don't have any code to show, otherwise I would have posted it earlier. Reason partly is that I have been trying to work out how to do this before starting to put this page together. I'll post the code once I've put the page together.

BenPleysier
Community Expert
Community Expert
July 9, 2010

To help you a bit more, here is an example

I have an employee_emp tabel with a field called state_emp which holds the name of the state where the employee lives.

I also have a state_sta table that I use as a lookup for the drop down list in the employee form. The id_sta field is the state ID and is the key that is used in the employee table. I also have a name_sta filed which holds the names of the states.

The drop down or select list is coded as follows

<select name="state_emp" id="state_emp"> the name of the field in which to post the value (employee table)
  <option value="">Select one...</option> the first option in the drop down list with no value
  <?php
  do {  php repeat
  ?>
  <option value="<?php echo $row_rsStates['id_sta']?>"<?php if (!(strcmp($row_rsStates['id_sta'], $row_rsemployee_emp['state_emp']))) {echo "SELECTED";} ?>><?php echo $row_rsStates['name_sta']?></option> get the values from the state table to populate the list If the value corresponds with the value of the employee table, then select that entry
    <?php
  } while ($row_rsStates = mysql_fetch_assoc($rsStates));
  $rows = mysql_num_rows($rsStates);
  if($rows > 0) {
      mysql_data_seek($rsStates, 0);
    $row_rsStates = mysql_fetch_assoc($rsStates); continue grabbing the values to populate the list until the values have been exhausted
  }
  ?>
</select> end of the select list

I hope this helps.

Ben

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!