I am a very inexpert php programmer, I ve done some asp.net programming but never php.
I need the requirement to add a dropdownlist with values from a table in the mysql database. I manually created a table training: id training date hour openseats
And I need to display this dates and hour in the dropdownlist, so once the user clikc submits this get stored into a table called jos_jquarks_users_acknowledge
Can you help me how to pupulate the dropdown?
Code:
{source}
<!-- You can place html anywhere within the source tags -->
<?php
// If the constant _JEXEC is not defined, quit now.
// This stops this script from running outside of the system.
defined( '_JEXEC' ) or die( 'Restricted access' );
?>
<?php
$user = JFactory::getUser();
$id = $user->get('id');
$name = $user->get('name');
$username = $user->get('username');
$department = $user->get('department');
$vardate = date("Y-m-d H:i:s");
$acknowledge = 1;
$courseTitle = $mainframe->getPageTitle();
$courseDate = ;
$courseHour =;
/***************************************/
$db = &JFactory::getDBO();
$query = "
INSERT INTO
`jos_jquarks_users_acknowledge`
(
course_name,
user_id,
employeeNumber,
department,
name,
acknowledge,
timeStamp,courseDate,
courseHour
)
VALUES
(
'{$courseTitle}',
'{$id}',
'{$username}',
'{$department}',
'{$name}',
'{$acknowledge}',
'{$vardate}',
'{$courseDate}',
'{courseHour}'
)";
$db->setQuery($query);
$db->query();
if($db->getErrorNum()) {
JError::raiseError( 500, $db->stderr());
}
?>
<form name="quiz_info" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<?php echo JText::_('Do you want to enroll into the course?') ; ?>
<? $queryCourses="SELECT training_id,training,trainingDate FROM training"; ?>
$result = mysql_query ($queryCourses);
echo "<select name=courseDates value=''>Date</option>";
// printing the list box select command
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id]>$nt[training]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";//Closing of list box
<input id="proceedButton" name="proceedButton" value="Acknowledge" type="submit" />
<input type="hidden" name="layout" value="default" /> <?php echo JHTML::_( 'form.token' ); ?>
</form>
{/source}