Forums

drop down with data of another table

ssuria 15 Oct, 2009
I have table1 with a form1 associated. When an user send a form, the table fills a record with user's id and the data of the form.
I have another table, table2, with table2.field1=table1.field1. And associated to users too.
I need show the content of table1.field1 for an specific user in a drop down. And I need show all the forms that an user fills for form 1.
For example: user 1 fills form1 with "project 1". Then fills again with "project 2". I have 2 forms type 1 for user 1. I need that this user can see these forms.
The user 2 fills the same form with "project 3".
Then, the user 1 opens form 2 and he has a drop down menu whit "project 1" and "project 2". But not "project 3" because it is from user 2.
How could I do this job? I don't know how could I do the menu for each form for each user, and how could I fill the drop down menu with correct data.

Thanks
GreyHead 16 Oct, 2009
Hi ssuria,

I find this confusing - too many tables :-(

If you want to show a list of form results you can do this in ChronoForms but ChronoConnectivity is better suited to it.

To get your drp-down you'l need to do a database query to get all the projects linked to user_1 and loop through the result to create your drop-down options.

Bob
Tryt 20 Oct, 2009
hello,

I want to make a dropdown selection field with data from a dbtable but after adding php script the form stopped to work (no fileds were published). After changing to the default CF code everything started to work fine. What am I doing wrong? the code attached below.

The original code:

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Placówka *</label>
    <select class="cf_inputbox validate-selection" id="select_4" size="1" title=""  name="select_4">
    <option value="">Wybierz placówkę</option>
      <option value="Przedszkole nr 2">Przedszkole nr 2</option>

//[several options]

<option value="Szkoła Podstawowa nr 77">Szkoła Podstawowa nr 77</option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>


The changed one:

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Placówka *</label>
    <select class="cf_inputbox validate-selection" id="select_4" size="1" title=""  name="select_4">
    <option value="">Wybierz placówkę</option>

<?php

$db  = mysql_connect('localhost', 'root', '');

mysql_select_db('przedszkola_11', $db);

$wynik = mysql_query('select title from jos_content where sectionid = 1');

$id = mysql_affected_rows();

for($i=0; $i<$id; $i++)
{
$wiersz = mysql_fetch_assoc($wynik);
echo '<option value="';
echo $wiersz["title"]);
echo '">';
echo $wiersz["title"];
echo '</option>';
}

mysql_free_result($wynik);
mysql_close($db);

?>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>


Thanks for help
GreyHead 20 Oct, 2009
Hi Tryt,

You have a stray ) in this line echo $wiersz["title"]); but actually I'd write the code a little differently using the Joomla db syntax:
<?php
$db =& JFactory::getDBO();
$query = "
  SELECT `title`
    FROM `#__content` 
    WHERE `sectionid` = 1 ;
";
$db->setQuery($query);
$results = $db->loadResultArray();
foreach ( $results as $v ) {
  echo "<option value='$v'>$v</option>";
}
?>

Bob
Tryt 21 Oct, 2009
hello Bob,

it worked! Great thanks!!!:*

Tryt
This topic is locked and no more replies can be posted.