Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Dropdown of all records from database + select current set record
    primarykey
    data
    text
    <p>I have a PHP dropdown of a list of groupnames (together with id, so it can be updated). In this FORM page you can change the groupname specified for an item by choosing possibilities from the dropdown coming out from the database. My code below works, but there must be a better way, because I get the first field as the currently set, and then all the possibilities, so I get this record twice.</p> <p>Example: <br> - Keyboard (Currently set) <br> - Speakers (Possible to choose, straight from DBS) <br> - Midi Controllers (Possible to choose, straight from DBS) <br> - Keyboard (Possible to choose, straight from DBS) <br> - Drum set (Possible to choose, straight from DBS) <br></p> <p>As you see I get the currently set record again.</p> <p>My code:</p> <pre><code>echo "&lt;select name='itemgroupid'&gt;"; // CHOOSE CURRENT SET RECORD AS SELECTED ITEM echo "&lt;option value='" . $itemgroupid . "'&gt;"; $selected=" SELECT item.itemid, itemgroup.itemgroupname, itemgroup.itemgroupid FROM item, itemgroup WHERE item.itemid=$itemid"; $selectedresult=mysql_query($query) or die("query fout " . mysql_error() ); while($record=mysql_fetch_array($selectedresult) ) { echo "" . $itemgroupname . "&lt;/option&gt;"; } // QUERY TO SHOW ALL POSSIBLE CHOOSABLE RECORDS FROM DATABASE $itemgroupquery="SELECT itemgroupname,itemgroupid FROM itemgroup"; $itemgroupqueryresult = mysql_query ($itemgroupquery); while($nt=mysql_fetch_array($itemgroupqueryresult)){ echo "&lt;option value=$nt[itemgroupid]&gt;$nt[itemgroupname]&lt;/option&gt;"; } echo "&lt;/select&gt;"; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload