Questions tagged [query-variables]

Query variables are inline-declared variables within a SQL statement.

Query variables are not supported in all RDBMS (eg MS SQL Server), but can be defined in MySQL, for example, using the := notation. They are useful, among other things, for performing window functions within a query (eg, rank, row number). See the following link for more details.

http://dev.mysql.com/doc/refman/5.0/en/user-variables.html

31 questions
9
votes
4 answers

Query with variables

Is it possible to set/read variables from within the query? pseudo code: SELECT animal_name, @tallest_animal = (select top 1 height from animal order by height desc) as tallest, @smallest_animal = (select top 1 height from animal order by…
freand
  • 161
  • 1
  • 1
  • 7
7
votes
1 answer

SELECT with query variables not using INDEXes

I was playing around (out of interest) with retrieving a tree of nodes in a simple adjacency list with a recursive query using local variables. The solution i have so far is fun but i wonder (and this is my only question) why MySQL refuses to use…
Kaii
  • 20,122
  • 3
  • 38
  • 60
6
votes
1 answer

How do I escape the colon (:) in a mysql query over jdbc that contains a variable assignment?

I'm trying to run a query that involves a custom variable over JDBC toward a MySQL 5.0 database (Hibernate 4 as the ORM): SET @rownum := 0; SELECT rnum FROM ( SELECT (@rownum := @rownum + 1) AS rnum, col_name_a FROM table_name WHERE…
watery
  • 5,026
  • 9
  • 52
  • 92
5
votes
4 answers

Getting current page url on wp-admin/admin dashboard?

Im trying to get the current page url while on the wp-admin/admin dashboard, is it possible? Im trying to use these codes but i can't seem to get it to work. global $wp; $current_page = add_query_arg( $wp->query_vars, home_url( $wp->request )…
Amenadiel
  • 173
  • 1
  • 3
  • 9
5
votes
2 answers

WordPress query_var by domain

I'd like to add a query variable to all queries coming from a certain domain. For example, mydomain.com and proxydomain.com both show the same WordPress site, but for users visiting via proxydomain.com, I'd like to be able to handle their queries…
HWD
  • 1,547
  • 7
  • 36
  • 72
4
votes
1 answer

Issues when using WordPress rewrite rules then accessing parameter using get_query_var

I'm developing a WP plugin and have a WordPress URL: (e.g.: http://localhost/testsite1/coder/?id=66), and have attempted to add a rewrite rule to http://localhost/testsite1/coder/66/ using the following rule: function add_mypage_rule(){ …
2
votes
1 answer

Matching a path with query variables in React

Assume I have the following pages on my website Page 1: example.com/somepage.php?action=a Page 2: example.com/somepage.php?action=b Page 3: example.com/somepage.php?action=b&other=c IMPORTANT NOTE: I do not have control of the URL paths, this is…
Greeso
  • 7,544
  • 9
  • 51
  • 77
2
votes
0 answers

Wordpress Custom Query Vars with pretty permalinks

I've been wracking my brain with this problem for the past couple of days, looking over all the potential solutions with no success. Here's what I'm trying to do. I want to create an SEO friendly url for pages that are created from an API. I have…
StephenB
  • 166
  • 2
  • 14
2
votes
1 answer

Wordpress: Required Multiple Slugs for a single page (Not custom post)

I am creating a plugin. I want to pass parameters in URL or you can say I want multiple URLs for same page(But this will load same page Not a Redirect). For example: http://www.ijmsbr.boxysolutions.com/publications-of-ijmsbr/?data=2016-11 I want…
Muhammad Akif
  • 76
  • 1
  • 6
1
vote
1 answer

Wordpress how to access a custom query variable from the url

I have the url http://localhost/testsite1/coder2/?id=71 with parameter id=71. As i am developing in WordPress I cannot use $_GET['id'] and so need to use get_query_var('id') to access the parameter. This however is not producing any result. When I…
1
vote
1 answer

Wordpress how to use a second form that only searches for posts?

I have two forms on my wordpress site, search.blade.php and blog-search.blade.php. search.blade.php is in the header of the site, and searches all content types. blog-search.blade.php is meant to only search post types. I'm using the following code…
1
vote
1 answer

Wordpress sorting posts by date and title using a dropdown

I'm trying to set up a drop-down that would sort my posts by Newest to oldest and Alphabetical. This is what I have so far: I'm declaring an empty variable, then a form where I can change the contents of this empty variable. This part doesn't…
1
vote
1 answer

Get orders by meta data via WooCommerce WC_Order_Query

How can I get a WooCommerce order by its number (instead of its ID)? I tried using wc_get_orders with custom args, like: wc_get_orders( array( 'number' => '1000' ) ); But it doesn't seem to work. Thanks!
OhMad
  • 6,871
  • 20
  • 56
  • 85
1
vote
1 answer

Wordpress pagination: get current page ('paged' query_var) from single page URL/template

I have an issue trying to get the current page from WP pagination. Here is my code: global $wp_query; $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; var_dump(get_query_var( 'paged' )); // HERE RETURN 0 EVERYTIME …
1
vote
2 answers

SQL pass variable to subquery

I can't pass variable to subquery. I have 2 different tables where need get all interview persons. Current my SQL SELECT empl.id AS id, (SELECT GROUP_CONCAT(interviewed_by SEPARATOR ', ') FROM ( SELECT …
Nefro
  • 195
  • 1
  • 11
1
2 3