I know eval is dangerous and evil but I need to use this for this situation. Basically I have two different databases that has the same table structure but with different data so I used a for each
loop to access both databases and a while loop to show all the databases results and I used eval so I can make the variables unique from each other. Everything seems to work well,
till I load the page and there are no errors but the page goes into a endless loop and it just keeps generating the first rows value which never progress showing the next rows value so how can I structure this better so I won't end up in a endless loop?
This is my code
<?php
$search_user_input='a';
$array_of_user_xs_database_name = array('agency_clients','agency_models');
$array_of_user_xs = array('client','model');
$iterator = new MultipleIterator();
$iterator->attachIterator(new ArrayIterator($array_of_user_xs_database_name));
$iterator->attachIterator(new ArrayIterator($array_of_user_xs));
foreach($iterator as $index => $value){
$user_xs_database_name= $value[0];
$user_x= $value[1];
$User_x= ucfirst($user_x);
eval('
$db_servername_getSearched'.$User_x.'="localhost";
$db_username_getSearched'.$User_x.'="jd";
$db_password_getSearched'.$User_x.'="1234";
$db_name_getSearched'.$User_x.'= $user_xs_database_name;
$db_connect_getSearched'.$User_x.'= new mysqli ($db_servername_getSearched'.$User_x.',$db_username_getSearched'.$User_x.',$db_password_getSearched'.$User_x.',
$db_name_getSearched'.$User_x.');
$db_query_getSearched'.$User_x.'= "SELECT uid, photo, CONCAT(first_name, \' \', last_name) AS name, signature_name, phone_number, email
FROM '.$user_x.'s WHERE CONCAT_WS(\' \','.$user_x.'s.first_name,'.$user_x.'s.last_name) LIKE \'%".$search_user_input."%\'
OR signature_name LIKE \'%".$search_user_input."%\' OR phone_number LIKE \'%".$search_user_input."%\' OR email LIKE \'%".$search_user_input."%\'";
$db_result_getSearched'.$User_x.'= $db_connect_getSearched'.$User_x.'->query($db_query_getSearched'.$User_x.');
');
$mysqli_result= eval('return $db_result_getSearched'.$User_x.';');
if($mysqli_result-> num_rows >= 1){
$mysqli_row= eval('return $db_row_getSearched'.$User_x.'= $db_result_getSearched'.$User_x.'->fetch_assoc();');
while($mysqli_row){
?>
<h1>
<?php
$photos= eval('return $db_row_getSearched'.$User_x.'["photo"];');
echo $photos;
?>
</h1>
<?php
}
}
}
?>