Last night I was thinking in a code part that I don't have it automated... That's why I don't has it has a object... One line of code is what I need to make it to a object a use it for a any project.
What I want is:
- Create a dynamic variables with a loop. (This is done and is a good idea)
- Create a dynamic SQL query with the variables that was created dynamic (This is what I want to do)
Here we create a dynamic variables with a for loop:
/* This variables has the inputs of an HTML
* inputs are the name of a input, in this example there are 2, email and pass
* inputs_val store the value of email and pass
$inputs;
$inputs_val;
// Starting with an array
$arrayName = array();
// Then with a for loop we fill the array
for ($i=0; $i < count($inputs_val); $i++) {
// While $i are less than 2 (email, pass) $i++
$var_nom = $inputs[$i];
$var_val = $inputs_val[$i];
$arrayName[$i] = $var_val;
// if we want to store the input name we use:
// $arrayName[$var_nom] = $var_val;
}
My question is here:
How you create an string SQL query looping the array?
for ($i=0; $i < count($arrayName); $i++) {
$query = "SELECT usr_email, usr_pass FROM tbl_usr WHERE usr_email='$arrayName[$i]' AND usr_pass='$arrayName[$i]' LIMIT 1;";
}
The error is there: usr_email='$arrayName[$i]' and usr_pass='$arrayName[$i]' Because when the loop start with 0 is OK for usr_email, but not for usr_pass and when the loop pass again is OK for usr_pass but not for usr_email...
I try with a $i2 = $i+1; but also doesn't work.
Suggest and ideas?