Jump to content

Formatting issue


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
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>
Edited by BrodaNoel
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

  • 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
https://forums.phpfreaks.com/topic/284554-formatting-issue/#findComment-1461357
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.