kms Posted December 5, 2013 Share Posted December 5, 2013 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/284554-formatting-issue/ Share on other sites More sharing options...
BrodaNoel Posted December 5, 2013 Share Posted December 5, 2013 (edited) 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 December 5, 2013 by BrodaNoel Quote Link to comment https://forums.phpfreaks.com/topic/284554-formatting-issue/#findComment-1461350 Share on other sites More sharing options...
Ch0cu3r Posted December 5, 2013 Share Posted December 5, 2013 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/284554-formatting-issue/#findComment-1461351 Share on other sites More sharing options...
kms Posted December 5, 2013 Author Share Posted December 5, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284554-formatting-issue/#findComment-1461352 Share on other sites More sharing options...
kms Posted December 5, 2013 Author Share Posted December 5, 2013 Thanks, Ch0cu3r but I do not have the user's TeamName, (which is the users full name) or the UserID in the while loop so it only will show once as you can see in the attachment above. Quote Link to comment https://forums.phpfreaks.com/topic/284554-formatting-issue/#findComment-1461353 Share on other sites More sharing options...
Solution Ch0cu3r Posted December 5, 2013 Solution Share Posted December 5, 2013 (edited) 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 December 5, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/284554-formatting-issue/#findComment-1461357 Share on other sites More sharing options...
kms Posted December 5, 2013 Author Share Posted December 5, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284554-formatting-issue/#findComment-1461364 Share on other sites More sharing options...
kms Posted December 5, 2013 Author Share Posted December 5, 2013 Got it. It was the > should have been < that fixed that. Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/284554-formatting-issue/#findComment-1461366 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.