Sydcomebak Posted August 14, 2008 Share Posted August 14, 2008 <?php $result = mysql_query("SELECT * FROM FamilyTbl INNER JOIN PeopleTbl ON (FamilyTbl.Name_ID = PeopleTbl.NameID) WHERE FamilyTbl.House_ID = '$address' ORDER BY NameLast, NameFirst ") OR die(mysql_error()); WHILE ($row = mysql_fetch_array($result) ) { echo $row[NameLast]. ", ". $row[NamePrefix]. " ". $row[NameFirst]. " ". $row[NameMiddle]. $row[NameSuffix]. " "; } ?> OK, some of these queries return A LOT of names. I'd like to be able to display them in columns in a table like so: Charne, Mr. Michael Glanger, Mrs. Karin Kling, Mr. Wayne Charne, Mrs. Suzette Glanger, Mr. Trevor Lazarow, Mrs. Fiona Charney, Mrs. Linda Jochelson, Mrs. Barbara Lazarow, Mr. Mark Charney, Mr. Norman Jochelson, Mr. Neil Norton, Mr. Charles Cohen, Mr. Brendan Karlan, Mr. Dennis Norton, Mrs. Jodi Cohen, Mrs. Joanna Karlan, Mrs. Helen Roy, Mr. Michael Flekser, Mrs. Jean Kling, Mrs. Danielle Roy, Mrs. Nicki Frysh, Dr. Howard Kling, Mrs. Melanie Tsafrir, Mrs. Lauren Frysh, Mrs. Sandra Kling, Mr. Nevil Tsafrir, Mr. Thomer That way it reads top to bottom THEN left to right. math-wise, it's simple to set up: <table> for row_loop=1 to numrows <tr> for col_loop = 1 to numcols <td> echo result(col_loop-1)*(numrows)+row_loop </td> next col_loop </tr> next row_loop </table> Anyone want to give this a shot? Link to comment https://forums.phpfreaks.com/topic/119668-solved-displaying-results-in-columns/ Share on other sites More sharing options...
revraz Posted August 14, 2008 Share Posted August 14, 2008 This might help http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Link to comment https://forums.phpfreaks.com/topic/119668-solved-displaying-results-in-columns/#findComment-616533 Share on other sites More sharing options...
lemmin Posted August 14, 2008 Share Posted August 14, 2008 You could just print columns only: $i=1; $max=11; echo "<table style=\"display:inline\">"; while ($row = mysql_fetch_array($result) ) { if (!($i%$max)) echo "</table><table style=\"display:inline\">"; echo "<tr><td>" . $row['name']; $i++; } Link to comment https://forums.phpfreaks.com/topic/119668-solved-displaying-results-in-columns/#findComment-616555 Share on other sites More sharing options...
Sydcomebak Posted August 14, 2008 Author Share Posted August 14, 2008 Here's the solution based on revraz's link: <?php $result = mysql_query("SELECT * FROM FamilyTbl INNER JOIN PeopleTbl ON (FamilyTbl.Name_ID = PeopleTbl.NameID) WHERE FamilyTbl.House_ID = '$address' ORDER BY NameLast, NameFirst ") OR die(mysql_error()); echo "<table>"; if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; WHILE ($row = mysql_fetch_array($result) ) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($row[FamilyID] != "" && $row[FamilyID] != null) echo "<td>"; echo $row[NameLast]. ", ". $row[NamePrefix]. " ". $row[NameFirst]. " ". $row[NameMiddle]. $row[NameSuffix]. " "; echo "</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results echo "</table>"; ?> Thanks revraz!!! Link to comment https://forums.phpfreaks.com/topic/119668-solved-displaying-results-in-columns/#findComment-616583 Share on other sites More sharing options...
Sydcomebak Posted August 14, 2008 Author Share Posted August 14, 2008 Revraz, this is a solution that displays in columns, but it goes left to right THEN up to down. I need to work this into an up to down THEN left to right. -Dave Link to comment https://forums.phpfreaks.com/topic/119668-solved-displaying-results-in-columns/#findComment-616608 Share on other sites More sharing options...
Dragoa Posted August 14, 2008 Share Posted August 14, 2008 Whoops, didn't see you made another topic: Ignore. Link to comment https://forums.phpfreaks.com/topic/119668-solved-displaying-results-in-columns/#findComment-616839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.