So what you want is to use MySQL’s “ORDER BY” feature:
SELECT Treatment FROM my_table WHERE Used=0 ORDER BY Allocation_number ASC LIMIT 1
So you look for all rows where Used=0, order (sort) them by Allocation_number in ascending order, and then pick the first row that matches. (“LIMIT 1”)
I’ll let you plug this into $wpdb as an exercise… 😉
Hope this helps!
Related Posts:
- Create a post builder skin in a plugin
- WP Query. Is there a maximum size?
- do_action() hook into load-(page)
- Howto check version of another plugin and then add a submenu page to it
- WordPress and a secondary database?
- password_reset hook is not working
- The Hook registration_errors was not called
- Hook into existing tinyMCE button
- plugin code is pulling information from database in one instance and not in other. What is wrong?
- How to get post ID with hooks publish_post, new_to_publish, etc
- WooCommerce search products between price range using WP_Query
- edit_user_profile and show_user_profile are not firing inside a class
- Template filter for custom taxonomy terms
- Add sub menu page in your plugin
- how to change automatic placing of social plugins below content?
- What exactly happens to function argument availability when using a filter?
- correct validate and sql query
- correct sql query
- SQL query, error
- Combining several CSS files into one for optimization
- the_post hook is not firing for me
- Why do plugins often ask to add in to templates?
- Deactivate JS Script in Plugin Shortcode
- remove_action not removing add_action from constructor
- Plugin Development – Functions or Hooks?
- How to get menu location in wp_update_nav_menu hook
- How do I add some javascript validation to the admin interface form’s onsubmit?
- Can my hooked uninstall class function access a global var declared in main plugin file?
- Flipping Book PHP Code? Any experience?
- Taxonomy Drill-Down / Plugin Help – hierarchical queries within plugin?
- How to customize a title by passing query string?
- Turning on output buffering in a wordpress plugin
- Hook for page Request?
- Display Plugin Panels Outside of Admin Areas
- Are there action hooks for comments?
- How to remove js ui library added by default by wordpress
- What is the best way to cache pages on WordPress
- How to use template_include hook with form submission?
- Adding Plugin Assets to Header
- Add item to the woocommerce dashboard menu from a plugin
- How to use the pre_option filter before a plugin loads?
- What are admin hooks
- Always get creating a new table with foreign key
- How do I add $_SESSION[”] to my wordpress page?
- WooCommerce: after install hook
- problem with sql query
- How to use filter to disable adding a product to wishlist?
- Save user total active time after login in wordpress [closed]
- add_query_arg not work in admin
- WordPress: Add custom add_filter for custom functions
- How to remove a class function from a plugin by using remove_action()?
- Advanced WordPress plugin activation detection
- profile_update hook doesn’t works inside a class
- wp_loaded with static Singleton
- wp_trash_post hook – problem with page updating if using wp_die
- Function added to hook “new_to_publish” not executing – custom plugin
- is it possible to hook every page style?
- Comment Approve – Add custom function when comment is approved
- How to use apply_filters?
- Plugin: Hooking up classes that have their own hooks
- Add action to custom Function
- Hook for altering the content of all wp mails
- Hook on creating a menu entry?
- What hook can I use to modify custom post data before it is displayed on the page?
- How to hook into action/filter call
- Quick press publish post hook
- Prevent plug-in scripts on a specific template?
- using wp_footer hook in a plugin
- How to deactivate my plugin upon deactivation of NextGen
- How to automatically activate users after registration without activation email?
- Creating a plugin that will display text on every page
- Hooks to run after a core upgrade?
- Plugin Hook When New Author Added
- Adding custom Field To The Posts Listing
- Hook for plugin to insert into entry-meta
- Why does “updated_post_meta” did not fire when uploading media other than image?
- Build a must-use plugin that tracks when other plugins are activated or deactivated
- Change Dashboard URL from wp-admin to wp-admin/index.php
- Activation flow of a plugin in a multisite environment
- Use a hook or filter, or overwrite this Gamipress function?
- Hook from plugin doesn’t fire up from external PHP script
- How to search post titles with whole words only, but not the exact word only?
- Add hook after content without formatting
- Change language on website and change currency with url query
- Using Remove Action Hook in Plugin
- WordPress Custom Hook with Class method
- Fail on admin_enqueue_scripts when I try it to upload a CSS file to my WordPress Plugin
- admin_post hook not firing function inside class
- How to remove a hook written with $this?
- Is there a hook similar to “save_post” which only fires AFTER the post is completely published?
- update_option_{$option} not working (do function after options are saved)
- Alternative Hook to the_content for Changing Background Color
- Unpublished Pages Failing To Appear On Custom Path
- add a hook of Woocommerce to a plugin but it only shows and doesn’t function properly
- Callback hooked to post_updated firing on new posts as well
- Randomize post (and page) IDs on generation
- save_post hook partly firing in update post
- My plugin runs on every single WordPress page, but I want it to run only on activation
- Displaying different content depending on variable
- The function called on the wp head hook becomes null