SV: [PHP-DB] Dynamic <td> generation when retrieving data from database...

From: Date: Fri, 23 May 2003 07:42:18 +0000
Subject: SV: [PHP-DB] Dynamic <td> generation when retrieving data from database...
Groups: php.db 
Request: Send a blank email to php-db+get-27982@lists.php.net to get a copy of this message
Try something like this: $n = mssql_num_rows($res); if ($n&1) $n=3; else $n=2; $i=0; echo '<tr>'; while (list($image,....) =mssql_fetch_row($res)) { $i++; if ($i == $n) { $i=0; echo "</tr>"; } if ($i==0) echo "<tr>"; echo "<td>$image</td> } echo "</tr></table>" hth Henrik Hornemann > -----Oprindelig meddelelse----- > Fra: Jonathan Villa [mailto:jvilla@isdesigndev.com] > Sendt: 23. maj 2003 06:10 > Til: php-db@lists.php.net > Emne: [PHP-DB] Dynamic <td> generation when retrieving data from > database... > > > Does anyone have a script which will do the following: > > For a shopping cart, I have the merchandise coming from the database > (image references, prices, ids, names, etc.) > > When I begin to display the results on the page I want to be able to > specify my <td> colspans and basic HTML table structure dynamically. > > For example, if result is 4, I want this > > <tr> > <td>image1</td> > <td>image2</td> > <td>image3</td> > </tr> > <tr> > <td colspan=3>image4</td> > </tr> > > if it's 5, > <tr> > <td>image1</td> > <td>image2</td> > <td>image3</td> > </tr> > <tr> > <td>image4</td> > <td colspan=2>image5</td> > </tr> > > etc. > > Any idea, scripts? > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.db (#27982) next »