meclive
asked on
PHP MS Access, populate drop-down/list box help.
I think this is a easy question, but im still learning php so don't laugh! Im using php to connect to a microsoft access database and i want to populate a drop-down box with the product numbers of the items in a table. I have seen many help pages on how to do this with my_sql but none for ms access as i need to find the equivelent of the "mysql_fetch_array()". I will post the code i have tried but not working below, it just takes ages to load and doesnt populate anything.
form.php
<?php
if (!$conn = new COM("ADODB.Connection"))
exit("Unable to create an ADODB connection<br>");
$strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("databasefile");
$conn->open($strConn);
$strSQL = "SELECT Part_No FROM products";
$rs = $conn->execute($strSQL);
$prodno = $rs->fields['Part_No'];
?>
<form name="update" method="post" action="deleted.php">
<select name="partno" size="1">
<?php
while (!$rs->EOF)
{
print "<option value=\"$prodno->value\">< /option>";
}
?>
</select>
<input type="submit" name="Submit" value="Delete">
</form>
<?php
}
?>
form.php
<?php
if (!$conn = new COM("ADODB.Connection"))
exit("Unable to create an ADODB connection<br>");
$strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("databasefile");
$conn->open($strConn);
$strSQL = "SELECT Part_No FROM products";
$rs = $conn->execute($strSQL);
$prodno = $rs->fields['Part_No'];
?>
<form name="update" method="post" action="deleted.php">
<select name="partno" size="1">
<?php
while (!$rs->EOF)
{
print "<option value=\"$prodno->value\"><
}
?>
</select>
<input type="submit" name="Submit" value="Delete">
</form>
<?php
}
?>
Hi,
Check out this article, which explained & shown how PHP interact with MS Access
http://www.phpbuilder.com/columns/siddarth20000228.php3
Hope This Helps!
Check out this article, which explained & shown how PHP interact with MS Access
http://www.phpbuilder.com/columns/siddarth20000228.php3
Hope This Helps!
try this..
$sql = "SELECT Part_No FROM products";
$rs = $conn->execute($strSQL);
while (!$rs->EOF) {
print "<option value=\"$rs->fields[0]\">$ rs->fields [0]</optio n>";
$rs->MoveNext(); // Moves to the next row
}
$sql = "SELECT Part_No FROM products";
$rs = $conn->execute($strSQL);
while (!$rs->EOF) {
print "<option value=\"$rs->fields[0]\">$
$rs->MoveNext(); // Moves to the next row
}
ASKER
I have tried the above mentioned code and i just get "Object[0]" in the drop-down box. Also i dont think my hosting allows a ODBC connection so is there any way of doing this? I have upped the points to 250 as i relly need an answer thanks.
ASKER
points upped to 335, anybody got an idea?
Hi,
replace this c:/test.mdb with your actual database..
It's working fine for me..
<?php
if (!$conn = new COM("ADODB.Connection"))
exit("Unable to create an ADODB connection<br>");
$strConn = "DRIVER={Microsoft access Driver (*.mdb)}; DBQ=" . realpath("c:/test.mdb");
$conn->open($strConn);
$strSQL = "SELECT Part_No FROM products";
$rs = $conn->execute($strSQL);
$prodno = $rs->fields["Part_No"];
?>
<form name="update" method="post" action="deleted.php">
<select name="partno" size="1">
<?php
while (!$rs->EOF)
{
print "<option value=\"$prodno->value\">$ prodno->va lue</optio n>";
$rs->MoveNext();
}
?>
</select>
<input type="submit" name="Submit" value="Delete">
</form>
replace this c:/test.mdb with your actual database..
It's working fine for me..
<?php
if (!$conn = new COM("ADODB.Connection"))
exit("Unable to create an ADODB connection<br>");
$strConn = "DRIVER={Microsoft access Driver (*.mdb)}; DBQ=" . realpath("c:/test.mdb");
$conn->open($strConn);
$strSQL = "SELECT Part_No FROM products";
$rs = $conn->execute($strSQL);
$prodno = $rs->fields["Part_No"];
?>
<form name="update" method="post" action="deleted.php">
<select name="partno" size="1">
<?php
while (!$rs->EOF)
{
print "<option value=\"$prodno->value\">$
$rs->MoveNext();
}
?>
</select>
<input type="submit" name="Submit" value="Delete">
</form>
ASKER
Thanks that works like a charm :0) you definatly get the points. The only problem i have is that i wish the first option in the drop-down box to either be blank or say "select from list".
ASKER
Also is there anyway i can order the drop down list box to put the results in order as they seem to be in a random order, thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works perfectly, thanks for all your help its much appreciated :0)
Set up an ODBC data source name, and then use PHP's ODBC functions (odbc_*) to access the database. They work pretty much the same as the mysql_* functions.
Doc.: http://www.php.net/manual/en/ref.uodbc.php
Good luck!