Jump to content

php/sql question


dmcdaniel

Recommended Posts

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.

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.