...
$id = $_SESSION['username'];
...
$result= mysql_query("select (nome, dia, mes, ano, turno, entra, sai) from persons where nome='$id'");
Que Tem Mal Este Select?
#1
Posted 21/01/2009, 14:27
#2
Posted 21/01/2009, 16:09
...
$id = $_SESSION['username'];
...
$result= mysql_query("select (nome, dia, mes, ano, turno, entra, sai) from persons where nome='$id'");
Boa Tarde!
Tenta dar uma simplificada na sql;
$result = mysql_query("SELECT nome, dia, mes, ano, turno, entra, sai FROM persons WHERE nome='".$id."'");
ou
$result = mysql_query("SELECT * FROM persons WHERE nome='".$id."'");
Saiba mais com rogerio.lamarques@gmail.com
#3
Posted 21/01/2009, 16:52
aparece uma tabela vazia...
aqui vai o codigo todo pra ver se me escapa algo...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Gestao horas</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="niceforms-default.css" />
</head>
<?php
function Diferenca($hora1, $hora2=""){
if($hora2==""){
$hora2 = date("H:i:s");
}
for($i=1;$i<=2;$i++){
${"horas".$i} = substr(${"hora".$i},0,2);
${"minutos".$i} = substr(${"hora".$i},3,2);
${"segundos".$i} = substr(${"hora".$i},6,2);
}
$dia = date(d);
$mes = date(m);
$ano = date(Y);
$segundos = mktime($horas2,$minutos2,$segundos2,$mes,$dia,$ano)-mktime($horas1,$minutos1,$segundos1,$mes,$dia,$ano);
return date("H:i:s",mktime(0,0,$segundos,$mes,$dia,$ano));
}
echo "<a href='index.php'>voltar</a><br />";
//echo "<a href='exportar.php'>exportar</a><br />";
//echo "<a href='exportar2.php'>exportar2</a><br />";
echo "<a href='exportar3.php'>exportar</a><br />";
$id = $_SESSION['username'];
$con = mysql_connect("localhost","root80","teste");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my", $con);
//$result = mysql_query("SELECT * FROM persons");
//$result= mysql_query("select nome, dia, mes, ano, turno, entra, sai from persons where nome='$id' or exit(mysql_error());
$result=mysql_query("select nome, dia, mes, ano, turno, entra, sai from persons where nome= ' ".$id." ' " );
//$result= mysql_query("select (nome, dia, mes, ano, turno, entra, sai) from persons where nome='$id'");
//DATEDIFF(entra, sai) as diferenca FROM
//SELECT campos, DATEDIFF(entra, sai) as diferenca FROM...
//$result2 = mysql_query("SELECT DATEDIFF(entra, sai) FROM persons");
//$data1 = $row['entra'];
//$data2 = $row['sai'];
//$datadif = echo datediff('$sai', '$entra');
//chamamos a função e imprimimos
//echo calcular_tempo_trasnc($entra, $sai);
echo "<table border='0' style='background-color:#F2B600' align='center'>
<tr>
<th>nome</th>
<th>dia</th>
<th>mes</th>
<th>ano</th>
<th>turno</th>
<th>entra</th>
<th>sai</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr style='background-color:#FFFF66'>";
echo "<td>" . $row['nome'] . "</td>";
echo "<td>" . $row['dia'] . "</td>";
echo "<td>" . $row['mes'] . "</td>";
echo "<td>" . $row['ano'] . "</td>";
echo "<td>" . $row['turno'] . "</td>";
echo "<td>" . $row['entra'] . "</td>";
echo "<td>" . $row['sai'] . "</td>";
// echo "<td>" . Diferenca($data1,$data2) . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
<body style="background-color: #CCCCCC"></body>
#5
Posted 21/01/2009, 17:22
$result = mysql_query('...') or die(mysql_error());
Veja se exibirá um erro mais claro.
[]'sAté mais
#6
Posted 21/01/2009, 17:40
print_r(); var_dump(); echo; e verifica as saidas e valores para ver se ta tudo como o esperado!
O_o
Abraços
***********************************************
Bachelor of Technology in Technology of Information, with great knowledge in Windows operating systems and Unix-Like (BSD, Ubuntu and Slackware), languages (PHP, JavaScript and MySQL), semantic (DHTML, Tableless, Ajax, MVC, OO) and analysis (manages projects based on PMI).
Developer in PHP, JAVA, Python, Objective-c MySQL, DHTML, CSS, JAVASCRIPT, JQUERY, JSON, SMARTY, MDB2, DOCTRINE, CAKEPHP. Linux desktop for work and MacOS. E-commerces, CRM and bussiness strategys
Love-me and be FREE use UniCes-Like .
#7
Posted 22/01/2009, 15:41
$result= mysql_query("select (nome, dia, mes, ano, turno, entra, sai) from persons where nome='$id'") or exit(mysql_error());
o erro q me aparece:
Operand should contain 1 column(s)
#8
Posted 23/01/2009, 16:12
$result= mysql_query("select (nome, dia, mes, ano, turno, entra, sai) as coluna from persons where nome= '".$id."'") or exit(mysql_error());
while($row = mysql_fetch_array($result))
{
echo "<tr style='background-color:#FFFF66'>";
echo "<td>" . $row['coluna'] . "</td>";
echo "</tr>";
}
PROBLEMA: tu está fazendo uma consulta retornando uma só coluna, e no entanto está tentando pegar várias. Por isso o erro:
"Operand should contain 1 column(s)" (Uma só coluna)
Edição feita por: _MELO_, 23/01/2009, 16:24.
0 user(s) are reading this topic
0 membro(s), 0 visitante(s) e 0 membros anônimo(s)