FrankieGee Posted June 6, 2013 Share Posted June 6, 2013 I am trying to figure this out. When I run the below code, I DO get spaces inside my <select><option></option></select> code, but I can not see anything but blank spaces. echo "<table border ='1' width='90%'><tr><td>"; echo "<select name=\"test\">"; $sql="select csname from customer where sacode = $sacode"; $rs=odbc_exec($conn,$sql); if (!$rs) echo"Error in SQL"; while($row=odbc_fetch_row($rs)) { echo "<option value=.$row[csname].</option>"; } echo "</select>"; echo "</td></tr>"; odbc_close($conn); echo "</table>"; When I run the same code to output into a table, everything is fine. Any ideas? Quote Link to comment Share on other sites More sharing options...
Barand Posted June 6, 2013 Share Posted June 6, 2013 try echo "<option value=\"{$row['csname']}\">{$row['csname']}</option>"; Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 6, 2013 Share Posted June 6, 2013 (edited) try echo "<option value=\"{$row['csname']}\">{$row['csname']}</option>"; To elaborate on what Barand provided, the problem was that the code was creating invalid HTML code. If the value from the DB was 'FOO' the option tag would have been created like this <option value=.FOO.</option> Instead it should be like this: <option value="FOO">FOO</option> which is what Barand's snippet will resolve. But, I would add that I would add a \n at the end of every line of HTML code (within double quotes) so it will put line-breaks in the HTML output. Otherwise, it becomes very difficult to debug the HTML. Edited June 6, 2013 by Psycho Quote Link to comment Share on other sites More sharing options...
FrankieGee Posted June 7, 2013 Author Share Posted June 7, 2013 Thank you Barand and Phyco. I have edited the script to reflect the proposed changes and I am still unable to actually see the results. Again, there is a 'placeholder' if you will, where the data should be. I have counted 102 rows inside the database for this user ($sacode =26) and 102 rows for the Select function. Quote Link to comment Share on other sites More sharing options...
Solution FrankieGee Posted June 7, 2013 Author Solution Share Posted June 7, 2013 Looking at this with fresh eyes, I was able to gain the results I needed. echo "<table border ='1' width='90%'><tr><td>"; echo "<select name=\"test\">"; echo "<option>Select Company</option>"; $sql="select csname from customer where sacode = $sacode order by csname"; $rs=odbc_exec($conn,$sql); if (!$rs) echo"Error in SQL"; while(odbc_fetch_row($rs)) { $csname=odbc_result($rs,"csname"); echo "<option value=\"$csname\">$csname</option>"; } echo "</select>"; echo "</td></tr>"; odbc_close($conn); echo "</table>"; Thanks everyone! I am sure to have more questions as this project progresses forward. 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.