TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Fetching from MySQL to multiple rows in a table (http://www.talkphp.com/absolute-beginners/6326-fetching-mysql-multiple-rows-table.html)

ban007 07-05-2012 08:13 AM

Fetching from MySQL to multiple rows in a table
 
Hi there!
I'm trying to fetch data from my Mysql db. The table has four columns. I need to put in each row a select form with db data inside. Using while() I get the data but only for the first row. Can anyone help me to get the select values/data in all rows?
The screenshot: http://ScrnSht.com/whkycz
The code in pastebin: http://pastebin.com/FcUK2twv
or here:
<?php
while ($item2 = $listado->fetch()) {
?>
<tr>
<td>Carril nš: <?php echo $item2['idCarrilTabaco'] ?><td>
<td>
<select name="descripcion" size ="1">
<?php while ($tabacos1 = $tabacos->fetch()) {?>
<option value='<?php echo $tabacos1['idTabaco']?>'><?php echo $tabacos1['descripcion']?></option>
<?php } ?>
</select>
</td>
<td><?php echo $item2['Capacidad'] ?></td>
<td><?php echo $item2['Cantidad'] ?></td>
</tr>
<?php
}
?>

Thanks all! Ban.

Solution: I created a variable using fetchAll() out of the while scope. But is there another way to do it?
It looks now like: http://pastebin.com/y1MGGT8V

tony 07-05-2012 02:00 PM

It's hard to know why the first pastebin wasn't working if we don't know how the variables $listado or $tabacos were created.

P.D. Usaste mysql_query o otra funcion o clase?


All times are GMT. The time now is 12:19 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0