the purpose of my page would be to display on top a dropmenu containing a list a weeks (populated from an access database).
when choosing a week it has to take the week-related data in the database and display it.
if the week chosen is the same as in the week field from "variable" database then the week-related data has to be editable.
this is what i got, feel free to quote and comment:
//odbc.php file used to connect to the database
<php?
$odbc = odbc_connect ('TestDB', 'root', '') or die( "Could Not Connect to ODBC Database testDB!" );
$odbc2 = odbc_connect ('variable', 'root', '') or die( "Could Not Connect to ODBC Database variable!" );
?>
//main file: main.php
//function equivalent to mysql_fetch_array (took this here on phpfreaks.com )
<php?
function odbc_fetch_array($result, $rownumber=-1) {
if (PHP_VERSION > "4.1") {
if ($rownumber < 0) {
odbc_fetch_into($result, $rs);
} else {
odbc_fetch_into($result, $rs, $rownumber);
}
} else {
odbc_fetch_into($result, $rownumber, $rs);
}
$rs_assoc = Array();
foreach ($rs as $key => $value) {
$rs_assoc[odbc_field_name($result, $key+1)] = $value;
}
return $rs_assoc;
}
?>
//function generating the dropdown menu:
<?php
function generate_box() {
include 'odbc.php';
$sql = "SELECT weeks FROM testdb";
$result = odbc_exec($odbc,$sql);
$entries = odbc_num_rows($result);
for($n = 0; $n <= $entries; $n++) {
$sql = "SELECT * FROM testdb WHERE ID = $n";
$result = odbc_exec($sql);
while ($row = odbc_fetch_array($result)) {
$options .= "<option value=\"{$row['weeknumber']}\">{$row['week']}< /option>";
}
}
return $options;
}
$options = generate_box();
?>
//display function called by the onChange in the form
<php?
function update (weekNumber){
include'odbc.php';
$query = odbc_exec($odbc,"select * from testdb where week = weeknumber");
$queryweek = odbc_exec($odbc2,"select * from variable ");
$row = odbc_fetch_array($queryweek);
if ($row['week'] != weeknumber)
{
//echo non editable text fields with data from database
while($row= odbc_fetch_array($query)){
//display fields in textareas
}
else{
//echoes same as above but editable
}
}
?>
//form
<from name="status">
<select name="week" onChange="update(options[selectedIndex].value);">
<?echo "$options"; ?>
</form>
thx a lot for any review