RynMan Posted May 3, 2009 Share Posted May 3, 2009 Hey guys First off, I'm a php rookie, so go easy! Basically, what I'm trying to do is this.... 1. Call on a query with several hundred records. 2. Display 2 of these fields (FirstName & LastName) for each record 3. Use PHP to create a new row for every 6 records until all records are done So the finished product will be a table with all of the people's names - with 6 columns, and many rows (record 1 in the first column, record 2 in the second column, 3 in the third etc). I know how to call my database, perform the query I want to pull the information from. I just don't know how to set up this loop. I need the PHP to basically say: - while there are still records, perform this task - for each 6 records, create a cell, then move to the next line and start creating a new row with the next 6 records. Thanks for any help you can lend me guys!! Link to comment https://forums.phpfreaks.com/topic/156623-looping-to-create-a-table/ Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 Something like this: $table = '<table><tr>'; $count = 0; while ($row = mysql_fetch_assoc($result)) { if (!empty($count) && $count % 6 == 0) { $table .= '</tr><tr>'; } $table .= '<td></td>'; // put your contents here } $table .= '</tr></table>'; Probably not the best way. Link to comment https://forums.phpfreaks.com/topic/156623-looping-to-create-a-table/#findComment-824716 Share on other sites More sharing options...
RynMan Posted May 3, 2009 Author Share Posted May 3, 2009 Something like this: $table = '<table><tr>'; $count = 0; while ($row = mysql_fetch_assoc($result)) { if (!empty($count) && $count % 6 == 0) { $table .= '</tr><tr>'; } $table .= '<td></td>'; // put your contents here } $table .= '</tr></table>'; Probably not the best way. Thanks ken. If I put my contents in there.... $table .= '<td></td>'; What I actually want is $row.["FirstName"] Will this not just repeat the same first name six times? Link to comment https://forums.phpfreaks.com/topic/156623-looping-to-create-a-table/#findComment-824717 Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 What I actually want is $row.["FirstName"] Will this not just repeat the same first name six times? Not unless your SQL returns the first name six times back to back. Link to comment https://forums.phpfreaks.com/topic/156623-looping-to-create-a-table/#findComment-824718 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.