Server side search two tables not working

Server side search two tables not working

fernarey18fernarey18 Posts: 11Questions: 6Answers: 0
edited April 2017 in Free community support

I have two tables: purchases (idcompra-idcliente-fecha_ingreso) and clients (name-surname-address ... etc). I need to search by first and last name in the second table but I do not know how to do it.

Server side:

$('#pagos').DataTable({
         "bProcessing": true,
                 "serverSide": true,
         "ajax":{
                url :"server_processing.php",
                type: "post",             
          }
        });

server_processing.php

$hostname = 'localhost';        
$dbname   = 'ap_formato'; 
$dbusername = 'root';
$dbpassword = '';

set_time_limit(150);
    
$connection = mysql_connect($hostname, $dbusername, $dbpassword);
if(!$connection) {
    die("database connecction failed." . mysql_error());
}

$db_select = mysql_select_db($dbname, $connection);
if(!$db_select) {
    die("database selection failed." . mysql_error());
}
$params = $columns = $totalRecords = $data = array();
$params = $_REQUEST;
$where = $sqlTot = $sqlRec = "";


if( !empty($params['search']['value']) ) {   
        //$where .=" WHERE ( nombre LIKE '%".$params['search']['value']."%' )";    
        /*$where .=" OR employee_salary LIKE '".$params['search']['value']."%' ";

        $where .=" OR employee_age LIKE '".$params['search']['value']."%' )";*/
    }

$sql = "SELECT * FROM compras "; 
$sqlTot .= $sql;
$sqlRec .= $sql;
$sqlRec .=  " ORDER BY fecha_ingreso DESC LIMIT ".$params['start']." ,".$params['length']; //" ORDER BY ". $columns[$params['order'][0]['column']]."   ".$params['order'][0]['dir'].

    $queryTot = mysql_query($sqlTot, $connection) or die("database error:". mysql_error($conn));


    $totalRecords = mysql_num_rows($queryTot);
    
    $queryRecords = mysql_query($sqlRec, $connection);

while( $row = mysql_fetch_array($queryRecords) ) {
         $tmp = array();
                 $sqlcli = "select * from clientes where idcliente = '$row[idcliente]'"; 
         $rescli = mysql_query($sqlcli);
         $tempc = mysql_fetch_array($rescli); 
         $nombre = ucwords($tempc['nombre'].' '.$tempc['apellido']);
         $tmp[0] = $nombre;
                 $data[] = $tmp;
This discussion has been closed.