PHP- Multiple variables in mysql query
Get the solution ↓↓↓I want to get the value from the {-code-6} column.
The mysql table looks like that:
ID | Epic[0] | Epic[1] | Epic[2] | Epic[3]
I have three variables where the informations are stored.
{-code-2}
I tried the following:
{-code-3}
Output looks like that:
{-code-4}
As you see{-code-5}
has the wrong syntaxing. The output for the working query should be like:{-code-6}
What is the right syntax handling in a mysql query like that?
Answer
Answer
Solution:
Use
$sql = "SELECT `${qualitybudget}[$budgetType]` FROM `randproppoints` WHERE id = '$itemlevel'";
instead. This way, the column name is exactly formatted as you wish and encapsulated.
Note that the syntax${xyz}
has to be used to make it clear that onlyxyz
is the name of the variable and that this is all to be printed here. Otherwise, PHP assumes it is an array and evaluates the following squared brackets for the same string insertion. Another example where this syntax has to be used is if for instance you had a variable$a = "thing";
and wanted
$b = "there are three $as";
to get"there are three things"
. It would not work as PHP would assume you address a variable$as
, but the fix would seem like this:
$b = "there are three ${a}s";
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: php_network_getaddresses: getaddrinfo failed: temporary failure in name resolution
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.