0
How do I add a prefixo
before my tabela
in php?
Follow my code below:
$table = 'news AS N, news_category AS NC';
if (strpos($table, ', ') !== false) {
foreach (array($table) as $key => $value) {
$db = $value;
}
echo $db;
} else {
echo 'FAIL';
}
You are returning me the following value: news AS N, news_category AS NC
Right now I’d like to leave it at that: prefixo_
news as n, prefixo_
news_category AS NC, within the code that I shared above. Remembering that I don’t want to so: $table = 'prefixo_news AS N, prefixo_news_category AS NC'
in the variable $table
, inside the if
or foreach.
It is possible?
This foreach loop of yours doesn’t make any sense. What do you want? It’s not quite clear what you want with this code, and probably the best solution is not the one you’re imagining.
– bfavaretto
Well, I’m a beginner, I need help, I wish for the
prefixo
, help me create good code?– user126995
That’s not it, you’re building a chunk of SQL, right? Under what conditions do you need the prefix and under which you don’t need it? And what is the variable for
$db
? It’s hard to help you without understanding what you’re trying to do.– bfavaretto
All right, come on, I’m putting together a snippet of SQL because the conditions I’m gonna need it for are at
function
, because I’m wanting to mount a single Function with two types of DB, the selection of normal DB and the selection of DB mult, the normal I already have, is like this: https://pastebin.com/cJApMWgg now I want to put a DB mult inside this function, so I’m using theif
withstrpos
to check if you have,
when choosing a table– user126995
What is a mult DB? Anyway, the other code seems right, and even has prefix treatment in the table. But I still do not understand your doubt.
– bfavaretto
multDB = I will open two tables at once, example: TABLE: News and TABLE: News_category, then you will read like this: readDB('news, news_category'); but with the code I have, you will only enter the prefix in the 1st table, being: readDB('prefixo_news, news_category'); this is where my problem comes in, I need the prefix to enter in the 2nd table also getting: readDB('prefixo_news, prefixo_news_category'); and so on, if you have 3 tables, 4, etc ... all entering the prefix in front.
– user126995
For all you said, I would create a new function to handle queries that involve more than one table.
– bfavaretto