Jump to content

Empty query?


padams

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.