I use a PHP file to store all the functions that I need in my project. One of them is the following:
function recuperar_opcion_plato_linea ($plato_id) { $hostname = 'localhost'; $username = 'xxxx'; $password = 'xxxxxxx'; try { $dbh = new PDO("mysql:host=$hostname;dbname=xxx", $username, $password); $sql = "SELECT * FROM tb_opciones_linea_comanda WHERE id_linea = '".$plato_id."'"; foreach ($dbh->query($sql) as $row) { return $row['id_opcion']; } $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } }
In another file, I call this function, but it gives only the first line of the query result, and there are at least 3 lines.
And this is part of the PHP code to call the recuperar_opcion_plato_linea function:
<?php do { ?> <p><?php echo $row_Recordset1['cantidad_pedido']." "; ?> <?php echo recuperar_nombre_plato($row_Recordset1['plato_pedido'])." "."$ ".$row_Recordset1['precio_linea']." ".$moneda?></p> <p><?php $opcion_selecionada = recuperar_opcion_plato_linea ($row_Recordset1['id_random']); echo recuperar_nombre_opcion($opcion_selecionada) ?></p> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
How can I get all rows from a query?
source share