[英]php mysql_query related queries
I'm trying to run a query to a table in my database and the id
field of the row that returns me to run a query to get the assistance
field of a different table. 我正在尝试对数据库中的表运行查询,该行的
id
字段返回使我运行查询以获取其他表的assistance
字段的行。
The code I'm trying to do is for a webService, my idea is to brand all fields of the first consultation separated by ;
我想做的代码是针对webService的,我的想法是将第一次咨询的所有字段都打上商标,并以
;
分隔;
but the assistance
of the second table, and separate each row returned by field :
但是在第二张表的
assistance
下,将field返回的每一行分开:
I just started programming in php, so I apologize if I did not express myself well or ask very basic things. 我刚刚开始用php编程,所以如果我表达不佳或提出非常基本的问题,我深表歉意。
Thanks for your time and help. 感谢您的时间和帮助。
CODE 码
if($tabla =="servicio")
{
$consulta = "SELECT `tipo` , `nombre` , `descripcion` , `hora` , `minuto` ,`lugar` , `duracion`,`fecha` , `horacero`, `id` FROM `".$tabla;
$resultado= mysql_query($consulta,$enlace);
$arraySalida = array();
while($registro = mysql_fetch_assoc ($resultado) ):
$consulta2 = "SELECT `asistencia` FROM `voluntarioServicio` WHERE id = `".$registro['id']."` AND emei = '".$emei."' ";
$resultado2= mysql_query($consulta,$enlace);
$registro2 = mysql_fetch_assoc ($resultado2);
$cadena = "{$registro['tipo']};{$registro['nombre']};{$registro['descripcion']};{$registro['hora']};{$registro['minuto']};{$registro['lugar']};{$registro['duracion']};{$registro['fecha']};{$registro['horacero']};{$registro2['asistencia']}";
$arraySalida[]= $cadena;
endwhile;
echo implode(":",$arraySalida);
}
Thanks, I have already solved. 谢谢,我已经解决了。 I leave here the code, I hope someone will serve.
我在这里留下代码,希望有人能为您服务。
CODE 码
$consulta = "SELECT tipo,nombre,descripcion,hora,minuto,lugar,duracion,fecha,horacero,id,asistencia FROM ( SELECT ".$tabla.".*, voluntarioServicio.asistencia FROM ".$tabla."left join voluntarioServicio on (".$tabla.".id=voluntarioServicio.id) ) as tabla";
$resultado= mysql_query($consulta,$enlace);
$arraySalida = array();
while($registro = mysql_fetch_assoc ($resultado) ):
$cadena = "{$registro['tipo']};{$registro['nombre']};{$registro['descripcion']};{$registro['hora']};{$registro['minuto']};{$registro['lugar']};{$registro['duracion']};{$registro['fecha']};{$registro['horacero']};{$registro['asistencia']}";
$arraySalida[]= $cadena;
endwhile;
echo implode(":",$arraySalida);
better SQL is 更好的SQL是
$consulta = "SELECT `table_a`.*, `table_b`.`asistencia`
FROM `".$tabla."` `table_a`
JOIN `voluntarioServicio` `table_b` ON `table_a`.`id` = `table_b`.`id`;";
because you get everything from inner select 因为你从内部选择中得到了一切
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.