Forum Moderators: coopster

Message Too Old, No Replies

PHP & MS Access - Display drop down menu

         

bcourt07

7:04 pm on Nov 25, 2008 (gmt 0)

10+ Year Member



Hello All,

I have an access database for class registration. Basically, I'm designing a form for the company's intranet page so end users can sign up for specific classes. What I need help with is displaying the class dates in a drop down list on the form.

Here is my config file


<?php
$conn = new COM ("ADODB.Connection") or die("Cannot start ADO");
$connStr = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=F:\Wellness Program\Courtney Test Folder\Class_Registration.mdb;";
$conn->open($connStr); //Open the connection to the database
?>


And here is what I have so far for the registration form

<?php
//config file contains connection to the database.
require("config.php");
$today = date("m/d/Y");
$Class_Date = "SELECT Class_Date, Class_Name FROM Class_Information WHERE Class_Name = '{$_POST['Class_Name']}' AND Class_Date >= '$today' ORDER BY Class_Date";
$rs = $conn->Execute($Class_Date);
?>
<title>Class Registration Form</title>
<form method=post action=?action=check>
<table border=1 align=center><tr><td>Employee Name: </td><td><input type=text name=Employee_Name></td></tr>
<tr>
<td>Extension: </td>
<td><input type=text name=Extension</td>
</tr>
<tr>
<td>Class Name:</td>
<td><select name=Class_Name>
<option value=ARP>ARP</option><option value=Skills Day>Skills Day</option></td></tr>
<tr>
<td>Class Dates:</td>
<td><select name=Class_Date><option value=$Class_Date>$rs->Fields['Class_Date']->Value</option></td>
</tr>
</form>
</table>

I would also like to put the Class_Name in a drop down from the table as well if possible. What I need the date field to do is select the class dates for the specific class name. If I confuse anyone, let me know. I'm good at confusing myself, hehe.

Any help is greatly appreciated!

Thanks so much!

phparion

4:32 pm on Nov 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think some code is hidden

$rs = $conn->Execute($Class_Date);

so I dont know how does your database interfacing class look like but it is very simple dear,

1 - select className, ClassDate from Access.

2 - run a loop e.g

$nameDropwDown=''; $dateDropDown='';

while($row=mysql_fetch_array($sqlRes)) {

$nameDropDown .= "<option>".$row['class_name']."</option>";
$dateDropDown .= "<option>".$row['class_date']."</option>";
}

and then in the form just print these variables e.g for class name

<select name=className>
<?php echo $nameDropDown; ?>
</select>

I hope it helps

bcourt07

2:30 pm on Dec 1, 2008 (gmt 0)

10+ Year Member



only slight problem is, it's an access database not mysql. will the mysql function still work though?

phparion

2:37 pm on Dec 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



study this Reading MS Access With PHP [devzone.zend.com]

bcourt07

7:46 pm on Dec 1, 2008 (gmt 0)

10+ Year Member



Thank you soo much for all of your help already! I have one more question though, how can I get the form to update with appropriate dates for the classes? For example, when an end-user selects the class "Excel Training", how can I get the form to update with just the excel training dates?

Thanks so much!

bcourt07

7:45 pm on Dec 2, 2008 (gmt 0)

10+ Year Member



Okay this might sound stupid, but how can I select class dates to display that in 2009? Here is my select statement

SELECT Class_Date FROM Class_Information WHERE Class_Date >= '$today' AND Class_Name = '{$_POST['Class_Name']}'

$today is set to today's date.

I'm not sure how to do it, and no matter what I try, the 2009 dates don't populate.

Thanks so much!

*Edit*
I figured it out, stupid me hehe.


SELECT Class_Date FROM Class_Information WHERE Class_Date >= '$today' OR Class_Date >= '01/01/2009' AND Class_Name = '{$_POST['Class_Name']}'