Jump to content

Recommended Posts

Is there a way to add to this by using infomation on my table.

 

Basically my table will have price and type and i want to add those 2 in the list so that it will look like this:

 

£12,000 - Steel

£12,500 - Wood

 

And because its a list box the user can then click which ever one and then i can submit it using a form ? ( i can do the form bit) but i cannot do the bit where by it creates the list in the box.. this is the html of the box so far:

 

<select name="Combobox3" size="2" id="Combobox3" style="position:absolute;left:343px;top:662px;width:223px;font-family:MS Shell Dlg;z-index:25">
</select>

Link to comment
https://forums.phpfreaks.com/topic/66645-creating-list-box-using-fields-on-my-db/
Share on other sites

Hi There,

 

Why not create a bespoke function like this and call it ...

 

// FUNCTION: dynamically creates and loads data into a <select> HTML object

// PARAMETERS required: FOUR Strings + ONE myDatabase Object

// RETURNS: HTML code for a drop down list

function create_dropdown_list($myDB, $SQL, $table, $attribute, $label)

 

  // initialise list

  $list = '<select name = "' . $label . '">';

 

  // run SQL query

  $dbResult = $myDB->ODBC_get_data($SQL, TABLE_ACCESS_ERROR . $table, TABLE_DATA_ERROR . $table);

 

  // create <option data>

    do

        {     

// capture data and assemble select options

$list .= "<option value='" . odbc_result ($dbResult, $attribute) . "' name='value'>" . odbc_result ($dbResult, $attribute) . "</option>";

       

        // fetch next row

        $row = odbc_fetch_row($dbResult);

        }

  while(TRUE == $row); 

 

// close list

  $list .= '</select>';

 

  return $list;

}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.