Jump to content

Recommended Posts

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> 

 

Link to comment
https://forums.phpfreaks.com/topic/131131-empty-query/
Share on other sites

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>   

Link to comment
https://forums.phpfreaks.com/topic/131131-empty-query/#findComment-680842
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/131131-empty-query/#findComment-680871
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.