Like SQL with multiple fields

Asked

Viewed 899 times

0

I want to make a select for a search of five fields (position, training, sex, schedule, photography). But it is not working.

Could someone tell me why?

<?php

$cargo = $_POST['cargo'];
$formacao = $_POST['formacao'];
$sexo = $_POST['sexo'];
$horario = $_POST['horario'];
$fotografia = $_POST['fotografia'];

$sql = mysql_query("SELECT * FROM tbl_cadastro_curriculo WHERE ((cargo LIKE '%".$cargo."%') OR (formacao LIKE '%".$formacao."%') OR (sexo LIKE '%".$sexo."%')
            OR (sexo LIKE '%".$sexo."%') OR (horario LIKE '%".$horario."%') OR (fotografia LIKE '%".$fotografia."%')) LIMIT ".$ini.",".$fim);

if ($sql && mysql_num_rows($sql) > 0) {     
   ...
}            
?>
  • Separating by commas post, training, schedule etc.. does not work?

  • I figured it out. I traded the OR for AND.

  • Put your answer to other people

1 answer

2

Here’s the answer I found:

<?php
$total = mysql_query('SELECT COUNT(*)TOTAL FROM tbl_cadastro_curriculo' );

$cargo = $_POST['cargo'];
$formacao = $_POST['formacao'];
$sexo = $_POST['sexo'];
$horario = $_POST['horario'];
$fotografia = $_POST['fotografia'];

$sql = mysql_query("SELECT * FROM tbl_cadastro_curriculo WHERE ((cargo LIKE '%".$cargo."%') AND (formacao LIKE '%".$formacao."%') AND (sexo LIKE '%".$sexo."%')
            AND (sexo LIKE '%".$sexo."%') AND (horario LIKE '%".$horario."%') AND (fotografia LIKE '%".$fotografia."%')) LIMIT ".$ini.",".$fim);

if ($sql && mysql_num_rows($sql) > 0) {
   .....
}            
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.