kelechi Posted March 9, 2015 Share Posted March 9, 2015 <?php $tsql = "SELECT bids.BidType +'[' + CAST(COUNT(*) as varchar)+ ']' solicitationName FROM bids inner JOIN status ON bids.Bidstatus = status.statusid where status.status='Open' GROUP BY bids.BidType UNION SELECT status.status +'[' + CAST(COUNT(*) as varchar)+ ']' solicitationName FROM bids INNER JOIN status ON bids.Bidstatus = status.statusid where status.status='Open' GROUP BY status.status UNION SELECT status.status +'[' + CAST(COUNT(*) as varchar)+ ']' solicitationName FROM bids INNER JOIN status ON bids.Bidstatus = status.statusid GROUP BY status.status"; $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['solicitationName'] . '" name="' . $row['solicitationName']. '">' . $row['solicitationName']. '</option>'; } ?> </select> Hello gurus, I am querying sql server database and trying to dynamically populate the values into a dropdown. So far, I don't even see a dropdown, let alone the values. Any ideas? Quote Link to comment Share on other sites More sharing options...
Solution Psycho Posted March 9, 2015 Solution Share Posted March 9, 2015 I don't see an opening <select> tag in your code. Plus, option tags don't have a name attribute. Also, it is better to build (the necessary) html in your code and output it later. This helps to separate the logic from the output <?php $tsql = "SELECT bids.BidType +'[' + CAST(COUNT(*) as varchar)+ ']' solicitationName FROM bids INNER JOIN status ON bids.Bidstatus = status.statusid where status.status='Open' GROUP BY bids.BidType UNION SELECT status.status +'[' + CAST(COUNT(*) as varchar)+ ']' solicitationName FROM bids INNER JOIN status ON bids.Bidstatus = status.statusid where status.status='Open' GROUP BY status.status UNION SELECT status.status +'[' + CAST(COUNT(*) as varchar)+ ']' solicitationName FROM bids INNER JOIN status ON bids.Bidstatus = status.statusid GROUP BY status.status"; $stmt = sqlsrv_query( $conn, $tsql); if( $stmt === false ) { echo "Error in executing query.</br>"; die( print_r( sqlsrv_errors(), true)); } $solicitationOptions = ''; while($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC)) { $solicitationOptions .= "<option value=\"{$row['solicitationName']}\">{$row['solicitationName']}</option>\n"; } //Perform ALL logic needed for the page - then output the HTML ?> <html> <head></head> <body> <select name=""> <?php echo solicitationOptions; ?> </select> Quote Link to comment Share on other sites More sharing options...
kelechi Posted March 9, 2015 Author Share Posted March 9, 2015 (edited) Great response! Thanks so much for the quick response. Works great. Ok, I lied. It is not populating the dropdown. Edited March 9, 2015 by kelechi Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 10, 2015 Share Posted March 10, 2015 I don't use MS SQL with PHP. Are you sure that your query isn't failing and that it it properly constructed such that there would be records? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.