Jump to content

Formatting issue


kms

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
https://forums.phpfreaks.com/topic/284554-formatting-issue/
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>
Link to comment
https://forums.phpfreaks.com/topic/284554-formatting-issue/#findComment-1461350
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
https://forums.phpfreaks.com/topic/284554-formatting-issue/#findComment-1461351
Share on other sites

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>";
	}
}
Link to comment
https://forums.phpfreaks.com/topic/284554-formatting-issue/#findComment-1461357
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.