I have a query in index.php and the exact same query in update.php. How can I have the query in a single location so it's easy to manage?
This is my query:
$sets=$_GET["sets"];
$sets = "'" . str_replace(array("'", ","), array("\\'", "','"), $sets) . "'";
// test code
$query = "
SELECT
*
FROM
`cards`
WHERE
`setName` in ($sets)
ORDER BY
`setName` DESC,
LIMIT
500
";
Include a header.php
, or a functions.php
. Then, define the queries within the file. You can then access them, after including them.
require 'header.php';
OR
include 'header.php';
function make_query($val)
{
$res = "SELECT * FROM users WHERE id = " . $val;
return $res;
}
Create a third file query.php
, put the query in this file (maybe in a variable) and include the file from both index.php
and update.php
.