I have to php pages that call the same mysql query
The first page would be:
<?php
include ('conection.inc');
$sql="SELECT mae_articulos.fecha_pub, mae_medios.des_medio,
mae_articulos.pagina, mae_periodistas.nom_periodista,
mae_periodistas.ap_periodista, mae_articulos.alto,
mae_articulos.ancho, mae_articulos.cod_articulo,
mae_articulos.ruta_imagen
FROM mae_articulos, mae_medios, mae_periodistas
WHERE mae_articulos.cod_medio = mae_medios.cod_medio AND
mae_articulos.cod_periodista = mae_periodistas.cod_periodista
AND (mae_articulos.cod_articulo = $art)";
$results=mysql_query($sql,$db);
$rows=mysql_fetch_array($results);
$fecha=$rows[0];
$medio=$rows[1];
$periodista=$rows[3]." ".$rows[4];
$pag=$rows[2];
$tamano=$rows[5]." cm. x ".$rows[6]." cm.";
$alto=doubleval($rows[5])*28.35;
$ancho=doubleval($rows[6])*28.35;
$imagen=$rows[8];
?>
The query in this page works well with an $art variable that is being passed.
The problem comes on another page where I have a an array being passed and I dont know
which would be the first value, so I have this:
<?php
include ('conection.inc');
// $cantidad is a variable that let me know the lenght of the array being passed (it
starts a 1) (checkboxes $clip[$i])
// I want to capture the first checkbox that has been selected so I can display the
results for that variable (a hidden input $art[$i] will give me the value)
// Later
$i=1;
while($i<=$cantidad){
if ((isset($clip[$i]))){
$cliptoshow=$art[$i];
break;
}
$i++;
}
$sql="SELECT mae_articulos.fecha_pub, mae_medios.des_medio,
mae_articulos.pagina, mae_periodistas.nom_periodista,
mae_periodistas.ap_periodista, mae_articulos.alto,
mae_articulos.ancho, mae_articulos.cod_articulo,
mae_articulos.ruta_imagen
FROM mae_articulos, mae_medios, mae_periodistas
WHERE mae_articulos.cod_medio = mae_medios.cod_medio AND
mae_articulos.cod_periodista = mae_periodistas.cod_periodista
AND (mae_articulos.cod_articulo = $cliptoshow)";
$results=mysql_query($sql,$db);
$rows=mysql_fetch_array($results);
$fecha=$rows[0];
$medio=$rows[1];
$periodista=$rows[3]." ".$rows[4];
$pag=$rows[2];
$tamano=$rows[5]." cm. x ".$rows[6]." cm.";
$alto=doubleval($rows[5])*28.35;
$ancho=doubleval($rows[6])*28.35;
$imagen=$rows[8];
?>
I would have this error Not a valid MySQL result argument at line xxx (line xxx will
be the one of "$rows=mysql_fetch_array($results);")
The wierd thing will be that when I put an echo $sql; line The Browser will show me
this:
SELECT mae_articulos.fecha_pub, mae_medios.des_medio,mae_articulos.pagina,
mae_periodistas.nom_periodista,
mae_periodistas.ap_periodista, mae_articulos.alto, mae_articulos.ancho,
mae_articulos.cod_articulo,
mae_articulos.ruta_imagen FROM mae_articulos, mae_medios, mae_periodistas WHERE
mae_articulos.cod_medio = mae_medios.cod_medio AND
mae_articulos.cod_periodista = mae_periodistas.cod_periodista AND
(mae_articulos.cod_articulo = 1026 // yes without the closing parentesis
Anyone have the slightest Idea why is this ocurring.
I am new at this php, and I think my while() code is bothering....
Thanks in advance
Fernando