dolcezza Posted January 9, 2008 Share Posted January 9, 2008 Can someone please educate me? If I var_dump($result) I get bool(false) What am I doing wrong? I am trying to create a dynamic dropdown from the database. Any help for a beginner is appreciated. $query = "SELECT * FROM authors"; $result = mysql_query($query); if(mysql_num_rows($result)) { // we have at least one user, so show all users as options in select form while($row = mysql_fetch_row($result)) { print("<option value=\"$row[0]\">$row[2]</option>"); } } else { print("<option value=\"\">No users created yet</option>"); } Quote Link to comment https://forums.phpfreaks.com/topic/85130-solved-dynamic-dropdown-returning-boolfalse/ Share on other sites More sharing options...
mmarif4u Posted January 9, 2008 Share Posted January 9, 2008 This is your complete code. Try like this: $query = "SELECT * FROM authors"; $result = mysql_query($query); if(mysql_num_rows($result)) { // we have at least one user, so show all users as options in select form while($row = mysql_fetch_row($result)) { echo "<select name='user'>"; echo "<option value='$row[0]'>$row[2]</option>"; } } else { echo "<option value=''>No users created yet</option>"; echo "</select>"; } Quote Link to comment https://forums.phpfreaks.com/topic/85130-solved-dynamic-dropdown-returning-boolfalse/#findComment-434296 Share on other sites More sharing options...
priti Posted January 9, 2008 Share Posted January 9, 2008 This is your complete code. Try like this: $query = "SELECT * FROM authors"; $result = mysql_query($query); if(mysql_num_rows($result)) { // we have at least one user, so show all users as options in select form while($row = mysql_fetch_row($result)) { echo "<select name='user'>"; echo "<option value='$row[0]'>$row[2]</option>"; } } else { echo "<option value=''>No users created yet</option>"; echo "</select>"; } I may be wrong but while($row = mysql_fetch_row($result)) { echo "<select name='user'>"; echo "<option value='$row[0]'>$row[2]</option>"; } in while loop we are creating <select>?? Quote Link to comment https://forums.phpfreaks.com/topic/85130-solved-dynamic-dropdown-returning-boolfalse/#findComment-434303 Share on other sites More sharing options...
priti Posted January 9, 2008 Share Posted January 9, 2008 i tried this and it worked form me kindly replicate at your end. echo '<select>'; if(mysql_num_rows($result)) { // we have at least one user, so show all users as options in select form while($row = mysql_fetch_row($result)) { echo "<option value=\"$row[0]\">$row[0]</option>"; --change this bold stuff according to your $row output } } else { echo "<option value=\"\">No users created yet</option>"; } echo '</select>'; Regards Quote Link to comment https://forums.phpfreaks.com/topic/85130-solved-dynamic-dropdown-returning-boolfalse/#findComment-434306 Share on other sites More sharing options...
dolcezza Posted January 9, 2008 Author Share Posted January 9, 2008 still getting no users... I have the select above it a bit further, because I wanted multi value etc.. Is this ok? There is something wrong I think with the query, because it isn't finding the users, but I don't know what. <form action="insertevent.php" method="POST"> Author: <select name="authorid[]" id="authorid" multiple="true">" <? $query = "SELECT * FROM authors"; $result = mysql_query($query); if(mysql_num_rows($result)) { // we have at least one user, so show all users as options in select form while($row = mysql_fetch_row($result)) { echo "<option value=\"$row[0]\">$row[2]</option>"; } } else { echo "<option value=\"\">No users created yet</option>"; } echo '</select>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/85130-solved-dynamic-dropdown-returning-boolfalse/#findComment-434309 Share on other sites More sharing options...
rajivgonsalves Posted January 9, 2008 Share Posted January 9, 2008 there must be an error change $result = mysql_query($query); to $result = mysql_query($query) or die("there was an error:".mysql_error()); and tell me if you get any errors Quote Link to comment https://forums.phpfreaks.com/topic/85130-solved-dynamic-dropdown-returning-boolfalse/#findComment-434310 Share on other sites More sharing options...
dolcezza Posted January 9, 2008 Author Share Posted January 9, 2008 it died after the word authors... ran nothing after that, including the other stuff on the page, but returned no error. If I look in my log(firefox) the last error is: Error: uncaught exception: Permission denied to call method Location.toString Quote Link to comment https://forums.phpfreaks.com/topic/85130-solved-dynamic-dropdown-returning-boolfalse/#findComment-434314 Share on other sites More sharing options...
mmarif4u Posted January 9, 2008 Share Posted January 9, 2008 Yeh Rajiv is right put mysql error reporting. try this code: $query = "SELECT * FROM authors"; $result = mysql_query($query) or die (mysql_error()); if(mysql_num_rows($result)) { // we have at least one user, so show all users as options in select form echo "<select name='user'>"; while($row = mysql_fetch_object($result)) { echo "<option value=\"$row->0\">$row->$row->2</option>"; } }else{ echo "<option value=''>No users created yet</option>"; echo "</select>"; } Quote Link to comment https://forums.phpfreaks.com/topic/85130-solved-dynamic-dropdown-returning-boolfalse/#findComment-434315 Share on other sites More sharing options...
rajivgonsalves Posted January 9, 2008 Share Posted January 9, 2008 see your view source of the browser what does it give ? Quote Link to comment https://forums.phpfreaks.com/topic/85130-solved-dynamic-dropdown-returning-boolfalse/#findComment-434319 Share on other sites More sharing options...
dolcezza Posted January 9, 2008 Author Share Posted January 9, 2008 got it working.... thank you very much working code: <form action="insertevent.php" method="POST"> Author: <select name="authorid[]" id="authorid" multiple="true">" <? $query = "SELECT * FROM authors ORDER BY authorlast ASC"; $result = mysql_query($query) or die("there was an error:".mysql_error()); if(mysql_num_rows($result)) { // we have at least one user, so show all users as options in select form while($row = mysql_fetch_row($result)) { echo "<option value=\"$row[0]\">$row[2]</option>"; } } else { echo "<option value=\"\">No users created yet</option>"; } echo '</select>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/85130-solved-dynamic-dropdown-returning-boolfalse/#findComment-434322 Share on other sites More sharing options...
rajivgonsalves Posted January 9, 2008 Share Posted January 9, 2008 Just out of curiosity what was the error!! Quote Link to comment https://forums.phpfreaks.com/topic/85130-solved-dynamic-dropdown-returning-boolfalse/#findComment-434324 Share on other sites More sharing options...
dolcezza Posted January 9, 2008 Author Share Posted January 9, 2008 I am not exactly sure... it just started working. That is why I posted the whole code. Although I am wondering if there was something wrong with the database connection, not the code? Possible? Thanks all! Quote Link to comment https://forums.phpfreaks.com/topic/85130-solved-dynamic-dropdown-returning-boolfalse/#findComment-434326 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.