Reputation: 1557
I have the following code that I am trying to use to dynamically populate a dropdownlist from SQL Server database.
<select name="BidType" class="inputstandard">
<option value=""></option>
<?
$tsql = mysql_query('SELECT BidID, BidType FROM BidTypes ORDER BY BidID ASC')
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
echo "Error in executing query.</br>";
die( print_r( sqlsrv_errors(), true));
}
while($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC)){
echo '<option value="' . $row['BidID'] . '" name="' . $row['BidType']. '">' . $row['BidType']. '</option>';
}
?>
</select>
When I run it, rather than populate dropdown with data from database, it just shows the following: . $row['BidType'].
Any ideas?
Sorry if the code is too elementary. I am learning. Thanks a lot in advance
Upvotes: 2
Views: 38
Reputation: 7791
You can't merge SQL Server functions sqlsrv_query
with MySql functions mysql_query
Try with this:
<select name="BidType" class="inputstandard">
<option value=""></option>
<?
mysql_connect("localhost", "your_user", "your_pass");
mysql_select_db("your_bd");
$tsql = mysql_query('SELECT BidID, BidType FROM BidTypes ORDER BY BidID ASC')
while($row = mysql_fetch_array($tsql, MYSQL_ASSOC)){
echo '<option value="' . $row['BidID'] . '" name="' . $row['BidType']. '">' . $row['BidType']. '</option>';
}
?>
</select>
Upvotes: 1