- Messages
- 7
- Likes
- 0
- Points
- 1
I have 2 snippets
----------
Snippet 'A' is an SQL query with following content:
function generalQuery {
global $wpdb;
$sql_query = "SELECT * from my_table1";
}
-----------
Snippet 'B' includes the content of Snippet A using 'do_shortcode' and writes out data from the database with following content:
do_shortcode('[wbcr_php_snippet id="id_of_A"]');
generalQuery();
$result = $wpdb->get_results($sql_query);
foreach($result as $row)
{
echo $row->db_item;
}
----------
This does not work, because I think the variable $sql_query from Snippet A is not passed to Snippet B.
---------
If I put all together in 1 snippet
$sql_query = "SELECT * from my_table1";
$result = $wpdb->get_results($sql_query);
foreach($result as $row)
{
echo $row->db_item;
}
It works.
While I want to use the same sql query in different codes, it would be nice to have it separated from the other snippets for reasons of redundance.
Thank you.
----------
Snippet 'A' is an SQL query with following content:
function generalQuery {
global $wpdb;
$sql_query = "SELECT * from my_table1";
}
-----------
Snippet 'B' includes the content of Snippet A using 'do_shortcode' and writes out data from the database with following content:
do_shortcode('[wbcr_php_snippet id="id_of_A"]');
generalQuery();
$result = $wpdb->get_results($sql_query);
foreach($result as $row)
{
echo $row->db_item;
}
----------
This does not work, because I think the variable $sql_query from Snippet A is not passed to Snippet B.
---------
If I put all together in 1 snippet
$sql_query = "SELECT * from my_table1";
$result = $wpdb->get_results($sql_query);
foreach($result as $row)
{
echo $row->db_item;
}
It works.
While I want to use the same sql query in different codes, it would be nice to have it separated from the other snippets for reasons of redundance.
Thank you.