Jump to content

Formatting issue


kms
Go to solution Solved by Ch0cu3r,

Recommended Posts

I am having some trouble getting the formatting correct displaying SQL data.  Below is the code but it is not lining up as it should just can't seem to get the tables right.  Here is the code.

echo "<table border='1'>
		<tr>
        <td width='90'><font size='2pt'>".TeamName."</td>
        <td ALIGN='left'><font size='2pt'>".UserID."</td>
        <td><font size='2pt'>".Departments."</td>
        <td><font size='2pt'>".Description."</td>
        <td><a href='csv.php'>Save to CSV file</a></td></tr><tr>
		<td style='vertical-align: top;'>".$name."</td>
        <td ALIGN='center' style='vertical-align: top;'>".$userid."</td><td>
		<table border='1' width='100%'>";
                
while($row = sqlsrv_fetch_array($stmt)){  


echo  "</td></tr><tr>
       <td>".$row[Departments]."</td>
	   <td>".$row[Description]."</td></tr>";
} 
	
    echo "</table>"; 
	echo "</table>";

Link to comment
Share on other sites

Hi!

Mmmmm... Are muy missing the "$" in TeamName var ?

 

Like that:

You have:

<td width='90'><font size='2pt'>".TeamName."</td>

And you should have:

<td width='90'><font size='2pt'>".$TeamName."</td>

In another hand, (css), check replace that:

<td ALIGN='left'><font size='2pt'>".UserID."</td>

and that

<td ALIGN='center' style='vertical-align: top;'>".$userid."</td><td>

for:

<td style='text-align:center'><font size='2pt'>".UserID."</td>

and that

<td style='vertical-align: top; text-align:center'>".$userid."</td><td>
Edited by BrodaNoel
Link to comment
Share on other sites

Your PHP code echo's a html table which first outputs 1 row with 5 columns. Then a new row with three columns, which in the third column you are outputting a table of results.

 

I think your code should be

echo "<table border='1'>
	<tr>
        <td width='90'><font size='2pt'>TeamName</td>
        <td ALIGN='left'><font size='2pt'>UserID</td>
        <td><font size='2pt'>Departments</td>
        <td><font size='2pt'>Description</td>
        <td><a href='csv.php'>Save to CSV file</a></td>
   	</tr>";

while($row = sqlsrv_fetch_array($stmt))
{  
	echo  "
    <tr>
       <td>".$row['TeamName']."</td>
       <td>".$row['UserID']."</td>
       <td>".$row['Department']."</td>
       <td>".$row['Description']."</td>
       <td></td>
    </tr>";
} 
	
echo "</table>"; 
Link to comment
Share on other sites

Thanks for the information.  The alignment I am having problems with is after the while loop.  It is not aligning with Departments or Description.  Attached file shows what it looks like from the browser.

 

post-166413-0-45839600-1386255033_thumb.jpg

  

Link to comment
Share on other sites

  • Solution

So you are listings all the departments the user belongs to? And want the Department and Descritions to be aligned?

 

Then try

echo "<table border='1'>
	<tr>
        <td width='90'><font size='2pt'>TeamName</td>
        <td ALIGN='left'><font size='2pt'>UserID</td>
        <td><font size='2pt'>Departments</td>
        <td><font size='2pt'>Description</td>
        <td><a href='csv.php'>Save to CSV file</a></td>
   	</tr>";

$row = sqlsrv_fetch_array($stmt); // get first result

echo "<tr>
   		<td>$TeamName</td>
   		<td>$UserID</td>
   		<td>".$row['Department']."</td>
   		<td>".$row['Description']."</td>
   		<td></td>
   	</tr>";

// if there is more than one result then list the remaining Department and Descriptions rows
if(sqlsrv_num_rows( $stmt ) > 1 )
{
	while($row = sqlsrv_fetch_array($stmt))
	{  
		echo "
		<tr>
	   		<td colspan='2'></td>
	   		<td>".$row['Department']."</td>
	   		<td>".$row['Description']."</td>
	   		<td></td>
	   	</tr>";
	}
}
Edited by Ch0cu3r
Link to comment
Share on other sites

Thanks I am looking at it right now.  Right off the bat I am trying to figure out why it is only listing the first line. Seems like there is something wrong with the if statement it is not looping through the while loop.

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.