dmcdaniel Posted April 30, 2010 Share Posted April 30, 2010 I have the following Code: <?php header("Cache-control: private"); header("Expires: 0"); session_start(); include('database.php'); $q = mysql_query("SELECT strName, strEmail, strFirstDay, strFirstDayDate, strLastDay, strLastDayDate FROM Vacation") or die(mysql_error()); $x=0; echo" <table> <tr> <th>Requests</th>"; while($row = mysql_fetch_array($q)){ extract($row); if ($x==0){ echo "</tr><tr>"; } $x++; if ($x == 3){ $x = 0; } echo "<td>$strName, $strEmail, $strFirstDay, $strFirstDayDate, $strLastDay, $strLastDayDate</td>"; } echo"</tr></table>"; ?> It formats it quite ugly. Right now it just formats it as: Results Derek McDaniel, [email protected], Monday, 05/03/2010, Tuesday, 05/04/2010 Derek McDaniel, [email protected], Monday, 05/03/2010, Tuesday, 05/04/2010 Mark Slatter, [email protected], Monday, 5/5, Friday, 5/9 Derek McDaniel, [email protected], Monday, 05/03/2010, Tuesday, 05/04/2010 I would like it to format like: Derek McDaniel, [email protected], Monday, 05/03/2010, Tuesday, 05/04/2010 Derek McDaniel, [email protected], Monday, 05/03/2010, Tuesday, 05/04/2010 Mark Slatter, [email protected], Monday, 5/5, Friday, 5/9 Derek McDaniel, [email protected], Monday, 05/03/2010, Tuesday, 05/04/2010 What would I need to change in the above code? I am still new with this PHP coding and have very little experience but I am a very fast learner. Link to comment https://forums.phpfreaks.com/topic/200289-phpsql-question/ Share on other sites More sharing options...
Ken2k7 Posted April 30, 2010 Share Posted April 30, 2010 That's basically 1 row, 1 column as opposed to 1 row, 3 columns. Just remove all those counters you have there for determining when to close and open a <tr> tag and just open and close it on the echo. Link to comment https://forums.phpfreaks.com/topic/200289-phpsql-question/#findComment-1051099 Share on other sites More sharing options...
dmcdaniel Posted April 30, 2010 Author Share Posted April 30, 2010 I tried to remove the counters but it made the formatting even worse. This is the new coding I tried: <?php header("Cache-control: private"); header("Expires: 0"); session_start(); include('database.php'); $q = mysql_query("SELECT strName, strEmail, strFirstDay, strFirstDayDate, strLastDay, strLastDayDate FROM Vacation") or die(mysql_error()); $x=0; echo" <table> <tr> <th>Requests</th>"; while($row = mysql_fetch_array($q)){ extract($row); echo "<td>$strName, $strEmail, $strFirstDay, $strFirstDayDate, $strLastDay, $strLastDayDate</td>"; } ?> Link to comment https://forums.phpfreaks.com/topic/200289-phpsql-question/#findComment-1051109 Share on other sites More sharing options...
Ken2k7 Posted April 30, 2010 Share Posted April 30, 2010 That's basically 1 row, 1 column as opposed to 1 row, 3 columns. Just remove all those counters you have there for determining when to close and open a <tr> tag and just open and close it on the echo. Please read the part in red. You forgot the <tr>. Link to comment https://forums.phpfreaks.com/topic/200289-phpsql-question/#findComment-1051113 Share on other sites More sharing options...
dmcdaniel Posted April 30, 2010 Author Share Posted April 30, 2010 Thanks. I fixed my issue but the closing tag was on a different echo line Link to comment https://forums.phpfreaks.com/topic/200289-phpsql-question/#findComment-1051118 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.