padams Posted November 3, 2008 Share Posted November 3, 2008 Keep getting the error "Query was empty". It sounds obvious what the problem is, but when I run any of the queries on the page by themselves in phpMyAdmin I get the results back as I would expect. There is no guidance as to which one of the many queries could be causing the problem. Also, when I run it in Dreamweaver Live it appears to work up to a point, but leaves several dropdown menus blank (which are populated by the results of a query). Here is a sample of the code I have been running: $silkrobestyle = "SELECT * FROM styles WHERE categoryID=13 ORDER BY styleID"; $silkrobestyle_query = mysql_query($silkrobestyle) or die(mysql_error()); $rsSilkrobestyle = mysql_fetch_assoc($silkrobestyle_query); The dropdown menu code is: <select name="style" class="dropdownboxstyles" id="style"> <?php while ($rsSilkrobestyle = mysql_fetch_assoc($silkrobestyle_query)) { ?> <option value="<?php echo $rsSilkrobestyle['styleID']; ?>"><?php echo $rsSilkrobestyle['style']; ?></option> <?php } ?> <?php mysql_data_seek($silkrobestyle_query, 0); ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/131131-empty-query/ Share on other sites More sharing options...
DarkWater Posted November 3, 2008 Share Posted November 3, 2008 Change the die(mysql_error()) construct to something like: $silkrobestyle_query = mysql_query($silkrobestyle) or die(mysql_error() . "Query: $silkrobestyle"); Quote Link to comment https://forums.phpfreaks.com/topic/131131-empty-query/#findComment-680840 Share on other sites More sharing options...
kenshintomoe225 Posted November 3, 2008 Share Posted November 3, 2008 hmm... Well..there is a pointer associated with mysql_fetch_assoc. Each time you call it, the pointer moves up to the next row. In your code, you call it once to populate $rsSilkrobestyle, and then again each time your while loop runs. Does that query return one row? If it does, thats probably the reason for your error. For example, your code could look like this $silkrobestyle = "SELECT * FROM styles WHERE categoryID=13 ORDER BY styleID"; $silkrobestyle_query = mysql_query($silkrobestyle) or die(mysql_error()); The dropdown menu code is: <select name="style" class="dropdownboxstyles" id="style"> <?php while ($rsSilkrobestyle = mysql_fetch_assoc($silkrobestyle_query)) { ?> <option value="<?php echo $rsSilkrobestyle['styleID']; ?>"><?php echo $rsSilkrobestyle['style']; ?></option> <?php } ?> <?php mysql_data_seek($silkrobestyle_query, 0); ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/131131-empty-query/#findComment-680842 Share on other sites More sharing options...
trq Posted November 3, 2008 Share Posted November 3, 2008 I don't understand why you have a call to mysql_data_seek()? This keeps placing the pointer back at the start so your loop will never iterate through any records. Quote Link to comment https://forums.phpfreaks.com/topic/131131-empty-query/#findComment-680843 Share on other sites More sharing options...
padams Posted November 3, 2008 Author Share Posted November 3, 2008 The mysql_data_seek() was lazy coding - we had copied and pasted something from earlier. Gone now! There are four dropdown menus, each populated by different queries, hitting the same table (styles) but querying using different criteria. The first one seems to work in Dreamweaver Live, but the three after do not. To complicate matters, there is this empty query error when we run it live on the web server. Quote Link to comment https://forums.phpfreaks.com/topic/131131-empty-query/#findComment-680871 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.