0
I am in dire need of any help from you with a little problem in PHP/Mysql.
I have a variable that has the names of medicines separated by commas (string), the amount of names stored in this variable can always vary, e.g.:
$medicamentos = "remedio1, remedio2, remedio3";
I take this string and separate the meds by exploding the commas:
$arrayMed = explode(", ",$medicamentos);
So far so good, but how I get these medicines already separated coming from this array so I can make a query in the BD as in the example below?:
$ReadMedicamentos = ExeRead("tabela_medicamentos", "WHERE medicamento_nome = '$variavel_vinda_do_array'");
while ($m = mysqli_fetch_assoc($ReadMedicamentos)):
extract($m);
endwhile;
I need all medicines in this array to be searched in the BD.
Note: I use the "Exeread" function to make queries in BD using Mysqli.
How can I make this consultation in BD for all medications that are present in Array?
From now on I appreciate any help.
Using your example
$arrayMed = explode(", ",$medicamentos);
then$arrayMed[0] === remedio1
,$arrayMed[1] === remedio2
and$arrayMed[2] === remedio3
. Then doforeach ($arrayMed as $remedio) { sua consulta }
– Augusto Vasques
So this "$remedio" variable that you put there, you’re going to get every turn of the foreach loop the name of a drug, this? And in this case this variable would take the place of my variable '$variavel_vinda_do_array" that I used in the example, this?
– Wanderson Borges
And in this case, I can use this variable "$remedio" instead of my variable ''$variavel_vinda_do_array" that I used in the example?
– Wanderson Borges
Exactly, this loop was built for this.
– Augusto Vasques
Excellent @Augustovasques, very good indeed. .
– Wanderson Borges