MySQL Forums
Forum List  »  Performance

how would you suggest to optimize theese quries?
Posted by: Darius Rokas
Date: November 29, 2021 11:26AM

$query_cl_main = mysqli_query($conn, $select_cl_main);

$num_cl_main = mysqli_num_rows($query_cl_main);



for($k=0;$k<$num_cl_main;$k++) {

$temp_cl_main = mysqli_fetch_array($query_cl_main);

$db_cl_id = $temp_cl_main['id'];

$db_cl_name = $temp_cl_main['cl_name'];

$db_cl_work = $temp_cl_main['cl_work'];

$db_cl_work = mysqli_fetch_array(mysqli_query($conn, "SELECT cl_work_name FROM clients_work WHERE id ='$db_cl_work'"))['cl_work_name'];

$db_cl_town = $temp_cl_main['cl_town'];

$db_cl_size = $temp_cl_main['cl_size'];

$db_cl_size_sna = mysqli_fetch_array(mysqli_query($conn, "SELECT cl_size_short_name FROM clients_size WHERE id ='$db_cl_size'"))['cl_size_short_name'];

$db_cl_size_des = mysqli_fetch_array(mysqli_query($conn, "SELECT cl_size_description FROM clients_size WHERE id ='$db_cl_size'"))['cl_size_description'];

$db_cl_ins_date = $temp_cl_main['cl_ins_date'];

$db_cl_web = $temp_cl_main['cl_web'];

if($db_cl_web != NULL) {

$db_cl_web = '<a class="btn btn-warning btn-sm btn-block" href="'.$db_cl_web.'" target="_blank"><i class="fas fa-external-link-alt"> </i></a>';

}else {

$db_cl_web = '<a class="btn btn-warning btn-sm btn-block" disabled target="_blank"><i class="fa fa-times"> </i></a>';

}

$db_cl_user_id = $temp_cl_main['cl_user_id'] ;

$db_cl_user_name = mysqli_fetch_array(mysqli_query($conn, "SELECT name FROM user_login WHERE u_id = '$db_cl_user_id'"))['name'];

$db_cl_user_surname = mysqli_fetch_array(mysqli_query($conn, "SELECT surname FROM user_login WHERE u_id = '$db_cl_user_id'"))['surname'];

$db_cl_status = $temp_cl_main['cl_status'];

$db_cl_id = $temp_cl_main['id'];

$call_count = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM calls WHERE cl_id = '$db_cl_id'"));

if($call_count > 9) {

$call_count = "9+";

}



$status = mysqli_fetch_array(mysqli_query($conn, "SELECT status FROM clients_status WHERE status_id ='$db_cl_status'"))['status'];

$bg_color = mysqli_fetch_array(mysqli_query($conn, "SELECT bg_color FROM clients_status WHERE status_id ='$db_cl_status'"))['bg_color'];

Maybe with joins?

Options: ReplyQuote


Subject
Views
Written By
Posted
how would you suggest to optimize theese quries?
225
November 29, 2021 11:26AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.