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, dmcdaniel@maximumcomm.com, Monday, 05/03/2010, Tuesday, 05/04/2010 Derek McDaniel, dmcdaniel@maximumcomm.com, Monday, 05/03/2010, Tuesday, 05/04/2010 Mark Slatter, mslatter@maximumcomm.com, Monday, 5/5, Friday, 5/9 Derek McDaniel, dmcdaniel@maximumcomm.com, Monday, 05/03/2010, Tuesday, 05/04/2010 I would like it to format like: Derek McDaniel, dmcdaniel@maximumcomm.com, Monday, 05/03/2010, Tuesday, 05/04/2010 Derek McDaniel, dmcdaniel@maximumcomm.com, Monday, 05/03/2010, Tuesday, 05/04/2010 Mark Slatter, mslatter@maximumcomm.com, Monday, 5/5, Friday, 5/9 Derek McDaniel, dmcdaniel@maximumcomm.com, 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. Quote Link to comment 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. Quote Link to comment 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>"; } ?> Quote Link to comment 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>. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.