What should Query be for a result of tuples in which the value of a column is 'x'?

2

I have the following query:

$select = "SELECT concat(mid(cpf,1,3),'.',mid(cpf,4,3),'.',mid(cpf,7,3),'-',mid(cpf,10,2)) as cpf, nome, genero, nome_cracha, rg, crm, crm_uf, rua, bairro, cep, cidade,
    estado, telefone, celular, fax, email, cna, ano_titulo_especialista, categoria_inscricao,
    forma_pagamento, dataconfirmacao, data from inscricao order by nome ASC";

and I want the variable $ x to know the value "category_inscription" (which the query will display). I want this to do the following:

if($x == "valor de categoria_inscricao" ){
   ... 
}

Edited

I'm using a code to convert table values to Excel. But I want it to appear instead of the column value, so I can show that if the column value is "x" what will appear in Excel is "y".

Follow the code:

<?php
if (!isset($_SESSION)) session_start();
if (!isset($_SESSION['usuario'])) {
    session_destroy();
    header("Location: index.php"); exit;
}
    include("conexao.php");

    $select = "SELECT concat(mid(cpf,1,3),'.',mid(cpf,4,3),'.',mid(cpf,7,3),'-',mid(cpf,10,2)) as cpf, nome, genero, nome_cracha, rg, crm, crm_uf, rua, bairro, cep, cidade,
    estado, telefone, celular, fax, email, cna, ano_titulo_especialista, categoria_inscricao,
    forma_pagamento, dataconfirmacao, data from inscricao order by nome ASC";



    $export = mysql_query($select) or die ("Sql error : ".mysql_error());

    $fields = mysql_num_fields($export);

    $header = "";
    $data = ""; 
    for ( $i = 0; $i<$fields; $i++ )
    {
    $header .= mysql_field_name($export, $i)."\t";
    }

    while( $row = mysql_fetch_row( $export ) )
    {
    $line = '';
    foreach( $row as $value )
    {
    if ((!isset($value)) || ($value == ""))
    {
    $value = "\t";
    }
    else
    {
    $value = str_replace( '"' , '""' , $value );
    $value = '"'.$value.'"'."\t";
    }
    $line .= $value;
    }
    $data .= trim( $line ) . "\n";
    }
    $data = str_replace( "\r" , "" , $data );

    if ( $data == "" )
    {
    $data = "\n(0) Records Found!\n";
    }

    $novonome = date('Ymd');

    header("Content-type: application/vnd.ms-excel");
    header("Content-Disposition: attachment; filename=".$novonome.".xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    print "$header\n$data";

    ?>
    
asked by anonymous 31.01.2014 / 16:46

2 answers

4

You have this example below. Note that not printf to compare it uses $row["id"] , that is, as the index of the array it uses the name of the field you return. In your case

if($row['valor de categoria_inscricao'] == $x)

record this ... otherwise serious.

mysql_fetch_array ()

<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
    die("Não foi possível conectar: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable");

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    printf("ID: %s  Name: %s", $row["id"], $row["name"]);
}

mysql_free_result($result);
?>
    
31.01.2014 / 17:12
1

You can restrict the search value in the query to do this. For example:

SELECT nome
FROM inscricao
WHERE categoria_inscricao = <valor desejado>
ORDERBY nome ASC

This query returns only the names of rows whose categoria_inscricao value has been pre-defined.

For more information about the WHERE clause, click here .

    
31.01.2014 / 16:57