Jump to content

[SOLVED] Tables Not Lining Up


twilitegxa

Recommended Posts

I don't think I have set anything that should make them not line up, but they don't for some reason. Can anyone help me with why? Here is the code:

 

<?php

session_start();

//Access Tracking Snippet

//set up static variables
$page_title = "listcharacters.php";
$user_agent = getenv("HTTP_USER_AGENT");
$date_accessed = date("Y-m-d");

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
$db = mysql_select_db("smrpg", $conn) or die(mysql_error());

//create and issue query
$sql = "insert into access_tracker values
('', '$page_title', '$user_agent', '$date_accessed')";
mysql_query($sql,$conn);
?>

<?php
//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
mysql_select_db("smrpg", $conn) or die(mysql_error());

//gather the scouts
$get_topics = "select id, identity,
date_format(create_time, '%b %e %Y at %r') as fmt_scout_create_time,
username, available from scouts where available = '0' order by create_time desc";
$get_topics_res = mysql_query($get_topics, $conn) or die(mysql_error());
if (mysql_num_rows($get_topics_res) < 1) {
//there are no topics, so say so
$display_block = "<p><em>No Scouts exist.</em></p>";
} else {
//get number of players
$get_num_posts = "select count(id) from scouts";
	$get_num_posts_res = mysql_query($get_num_posts, $conn)
		or die(mysql_error());
	$num_posts = mysql_result($get_num_posts_res, 0, 'count(id)');

//create the display string
$display_block = "
<table cellpadding=3 cellspacing=3 border=1>
<tr>
<th>SCOUTS</th>";
if ($num_posts<10){

         $num_posts = "0".$num_posts;

      }
  $display_block .= "
<th># OF PLAYERS: $num_posts</th>
</tr>";

while ($topic_info = mysql_fetch_array($get_topics_res)) {
	$topic_id = $topic_info['id'];
	$topic_title = ucwords(strtolower($topic_info['identity']));
	$topic_create_time = $topic_info['fmt_scout_create_time'];
	$topic_owner = $topic_info['username'];

	//add to display
	$display_block .= "
	<tr>
	<td><a href=\"showprofile_scouts.php?id=$topic_id\">
		<strong>$topic_title</strong></a><br>
		<em>Created on $topic_create_time by</em> <strong>$topic_owner</strong></td>
		<td align=center> </td>
		</tr></table>";
	}
}

//gather the knights
$get_knights = "select id, identity,
date_format(create_time, '%b %e %Y at %r') as fmt_knight_create_time,
username, available from knights where available = '0' order by create_time desc";
$get_knights_res = mysql_query($get_knights, $conn) or die(mysql_error());
if (mysql_num_rows($get_knights_res) < 1) {
//there are no knights, so say so
$display_block .= "<p><em>No Knights exist.</em></p>";
} else {
//get number of players
$get_num_knights = "select count(id) from knights";
	$get_num_knights_res = mysql_query($get_num_knights, $conn)
		or die(mysql_error());
	$num_knights= mysql_result($get_num_knights_res, 0, 'count(id)');

//create the display string
$display_block .= "<table cellpadding=3 cellspacing=3 border=1>
<tr>
<th>KNIGHTS</th>";
if ($num_knights<10){

         $num_knights = "0".$num_knights;

      }
  $display_block .= "
<th># OF PLAYERS: $num_knights</th>
</tr>";

while ($knight_info = mysql_fetch_array($get_knights_res)) {
	$knight_id = $knight_info['id'];
	$knight_identity = ucwords(strtolower($knight_info['identity']));
	$knight_create_time = $knight_info['fmt_knight_create_time'];
	$knight_username = $knight_info['username'];

	//add to display
	$display_block .= "
	<tr>
	<td><a href=\"showprofile_knights.php?id=$knight_id\">
		<strong>$knight_identity</strong></a><br>
		<em>Created on $knight_create_time by</em> <strong>$knight_username</strong></td>
		<td align=center> </td>
		</tr></table>";
	}
}

//gather the fdark_warriors
$get_fdark_warriors = "select id, identity,
date_format(create_time, '%b %e %Y at %r') as fmt_fdark_warrior_create_time,
username, available from fdark_warrior where available = '0' order by create_time desc";
$get_fdark_warriors_res = mysql_query($get_fdark_warriors, $conn) or die(mysql_error());
if (mysql_num_rows($get_fdark_warriors_res) < 1) {
//there are no female dark warriors, so say so
$display_block .= "<p><em>No Female Dark Warriors exist.</em></p>";
} else {
//get number of players
$get_num_fdark_warriors = "select count(id) from fdark_warrior";
	$get_num_fdark_warriors_res = mysql_query($get_num_fdark_warriors, $conn)
		or die(mysql_error());
	$num_fdark_warriors = mysql_result($get_num_fdark_warriors_res, 0, 'count(id)');

//create the display string
$display_block .= "<table cellpadding=3 cellspacing=3 border=1>
<tr>
<th>FEMALE DARK WARRIORS</th>";
if ($num_fdark_warriors<10){

         $num_fdark_warriors = "0".$num_fdark_warriors;

      }
  $display_block .= "
<th># OF PLAYERS: $num_fdark_warriors</th>
</tr>";

while ($fdark_warrior_info = mysql_fetch_array($get_fdark_warriors_res)) {
	$fdark_warrior_id= $fdark_warrior_info['id'];
	$fdark_warrior_identity = ucwords(strtolower($fdark_warrior_info['identity']));
	$fdark_warrior_create_time = $fdark_warrior_info['fmt_fdark_warrior_create_time'];
	$fdark_warrior_username = $fdark_warrior_info['username'];

	//add to display
	$display_block .= "
	<tr>
	<td><a href=\"showprofile_fdark_warrior.php?id=$fdark_warrior_id\">
		<strong>$fdark_warrior_identity</strong></a><br>
		<em>Created on $fdark_warrior_create_time by</em> <strong>$fdark_warrior_username</strong></td>
		<td align=center> </td>
		</tr></table>";
	}
}	

//gather the male dark_warriors
$get_mdark_warriors = "select id, identity,
date_format(create_time, '%b %e %Y at %r') as fmt_mdark_warrior_create_time,
username, available from mdark_warrior where available = '0' order by create_time desc";
$get_mdark_warriors_res = mysql_query($get_mdark_warriors, $conn) or die(mysql_error());
if (mysql_num_rows($get_mdark_warriors_res) < 1) {
//there are no male dark warriors, so say so
$display_block .= "<p><em>No Male Dark Warriors exist.</em></p>";
} else {
//get number of players
$get_num_mdark_warriors = "select count(id) from mdark_warrior";
	$get_num_mdark_warriors_res = mysql_query($get_num_mdark_warriors, $conn)
		or die(mysql_error());
	$num_mdark_warriors = mysql_result($get_num_mdark_warriors_res, 0, 'count(id)');

//create the display string
$display_block .= "<table cellpadding=3 cellspacing=3 border=1>
<tr>
<th>MALE DARK WARRIORS</th>";
if ($num_mdark_warriors<10){

         $num_mdark_warriors = "0".$num_mdark_warriors;

      }
  $display_block .= "
<th># OF PLAYERS: $num_mdark_warriors</th>
</tr>";

while ($mdark_warrior_info = mysql_fetch_array($get_mdark_warriors_res)) {
	$mdark_warrior_id= $mdark_warrior_info['id'];
	$mdark_warrior_identity = ucwords(strtolower($mdark_warrior_info['identity']));
	$mdark_warrior_create_time = $mdark_warrior_info['fmt_mdark_warrior_create_time'];
	$mdark_warrior_username = $mdark_warrior_info['username'];

	//add to display
	$display_block .= "
	<tr>
	<td><a href=\"showprofile_mdark_warrior.php?id=$mdark_warrior_id\">
		<strong>$mdark_warrior_identity</strong></a><br>
		<em>Created on $mdark_warrior_create_time by</em> <strong>$mdark_warrior_username</strong></td>
		<td align=center> </td>
		</tr>";
	}
}	

	//close up the table
	$display_block .= "</table>";
?>
<html>
<head>
<title>Sailor Moon RPG - Characters</title>
<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css); 
/*]]>*/
</style>
</head>
<body>
<!-- HEADER -->
<h1 class="logo">Sailor Moon RPG</h1>
<!-- /HEADER -->
<?php include("topnav.php"); ?>
<div id="main">
<?php include("includes/log.php"); ?>
<?php include("mainnav.php"); ?>
<h1>Characters In Sailor Moon RPG</h1>
<h3>Would you like to <a href="creationform.php">create a character</a>?</h3>
<?php print $display_block; ?>
</div>
<?php include("bottomnav.php"); ?><!-- FOOTER -->
<!-- FOOTER -->
<div id="footer_wrapper">
<div id="footer">
<p>Sailor Moon and all characters
are<br /> 
trademarks of Naoko Takeuchi.</p>
<p>Copyright © 2009 Liz Kula. All rights reserved.<br />
A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p>
<div id="foot-nav">
<ul>
<li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>
</ul>
</div>
</div>
</div>
<!-- /FOOTER -->
</body>
</html>

 

The first and last table line up and the two middle ones do, but they do not all line up. Here is a screen shot:

 

http://s452.photobucket.com/albums/qq246/twilitegxa/?action=view&current=screenshot.jpg

Link to comment
Share on other sites

The problem is not actually php. Try setting some fixed widths for your tables, so everywhere you have <td> change it set the width you want: <td width="200"> This will fix the width of each cell, right now your table is only going to be the size of whatever is inside it.

Link to comment
Share on other sites

This is an HTML question.

 

You should try to have the HTML ready before embedding into PHP.

 

Create a new html page, create and line up the tables the way you want, then once you have it how you want, embed it into PHP. That should help you tons :)

Link to comment
Share on other sites

It's okay, I adjusted the width of the tables, and I left the tables, and just duplicated the table information with the table headers when the "no records" part displayed because I wanted those to line up with the other tables. There are four tables, and sometimes there will be records displayed from them and sometimes not, so I need it all to line up regardless. Here's the way I did it:

 

<?php

session_start();

//Access Tracking Snippet

//set up static variables
$page_title = "listcharacters.php";
$user_agent = getenv("HTTP_USER_AGENT");
$date_accessed = date("Y-m-d");

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
$db = mysql_select_db("smrpg", $conn) or die(mysql_error());

//create and issue query
$sql = "insert into access_tracker values
('', '$page_title', '$user_agent', '$date_accessed')";
mysql_query($sql,$conn);
?>

<?php
//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
mysql_select_db("smrpg", $conn) or die(mysql_error());

//gather the scouts
$get_topics = "select id, identity,
date_format(create_time, '%b %e %Y at %r') as fmt_scout_create_time,
username, available from scouts where available = '0' order by create_time desc";
$get_topics_res = mysql_query($get_topics, $conn) or die(mysql_error());
if (mysql_num_rows($get_topics_res) < 1) {
//there are no topics, so say so
$display_block = "<table cellpadding=3 cellspacing=3 border=0 class=list_tables>
<tr>
<th><u>SCOUTS</u></th>";
//get number of players
$get_num_posts = "select count(id) from scouts where available = '0'";
	$get_num_posts_res = mysql_query($get_num_posts, $conn)
		or die(mysql_error());
	$num_posts = mysql_result($get_num_posts_res, 0, 'count(id)');

if ($num_posts<10){

         $num_posts = "0".$num_posts;

      }
  $display_block .= "
<th><u># OF PLAYERS: $num_posts</u></th>
</tr>
<tr>
<td width=400><em>No Scouts exist.</em></td></tr>";
} else {

//create the display string
$display_block = "<table border=0><tr><td>
<table cellpadding=3 cellspacing=3 border=0 class=list_tables>
<tr>
<th><u>SCOUTS</u></th>";

//get number of players
$get_num_posts = "select count(id) from scouts where available = '0'";
	$get_num_posts_res = mysql_query($get_num_posts, $conn)
		or die(mysql_error());
	$num_posts = mysql_result($get_num_posts_res, 0, 'count(id)');

if ($num_posts<10){

         $num_posts = "0".$num_posts;

      }
  $display_block .= "
<th><u># OF PLAYERS: $num_posts</u></th>
</tr>";

while ($topic_info = mysql_fetch_array($get_topics_res)) {
	$topic_id = $topic_info['id'];
	$topic_title = ucwords(strtolower($topic_info['identity']));
	$topic_create_time = $topic_info['fmt_scout_create_time'];
	$topic_owner = $topic_info['username'];

	//add to display
	$display_block .= "
	<tr>
	<td width=400><a href=\"showprofile_scouts.php?id=$topic_id\">
		<strong>$topic_title</strong></a><br>
		<em>Created on $topic_create_time by</em> <strong>$topic_owner</strong></td>
		<td align=center> </td>
		</tr></table>";
	}
}

//gather the knights
$get_knights = "select id, identity,
date_format(create_time, '%b %e %Y at %r') as fmt_knight_create_time,
username, available from knights where available = '0' order by create_time desc";
$get_knights_res = mysql_query($get_knights, $conn) or die(mysql_error());
if (mysql_num_rows($get_knights_res) < 1) {
//there are no knights, so say so
$display_block .= "<table cellpadding=3 cellspacing=3 border=0 class=list_tables>
<tr>
<th><u>KNIGHTS</u></th>";
//get number of players
$get_num_knights = "select count(id) from knights where available = '0'";
	$get_num_knights_res = mysql_query($get_num_knights, $conn)
		or die(mysql_error());
	$num_knights= mysql_result($get_num_knights_res, 0, 'count(id)');
if ($num_knights<10){

         $num_knights = "0".$num_knights;

      }
  $display_block .= "
<th><u># OF PLAYERS: $num_knights</u></th>
</tr>
<tr>
<td width=400><em>No Knights exist.</em></td></tr>";
} else {
//get number of players
$get_num_knights = "select count(id) from knights where available = '0'";
	$get_num_knights_res = mysql_query($get_num_knights, $conn)
		or die(mysql_error());
	$num_knights= mysql_result($get_num_knights_res, 0, 'count(id)');

//create the display string
$display_block .= "<table cellpadding=3 cellspacing=3 border=0 class=list_tables>
<tr>
<th><u>KNIGHTS</u></th>";
if ($num_knights<10){

         $num_knights = "0".$num_knights;

      }
  $display_block .= "
<th><u># OF PLAYERS: $num_knights</u></th>
</tr>";

while ($knight_info = mysql_fetch_array($get_knights_res)) {
	$knight_id = $knight_info['id'];
	$knight_identity = ucwords(strtolower($knight_info['identity']));
	$knight_create_time = $knight_info['fmt_knight_create_time'];
	$knight_username = $knight_info['username'];

	//add to display
	$display_block .= "
	<tr>
	<td width=400><a href=\"showprofile_knights.php?id=$knight_id\">
		<strong>$knight_identity</strong></a><br>
		<em>Created on $knight_create_time by</em> <strong>$knight_username</strong></td>
		<td align=center> </td>
		</tr></table>";
	}
}

//gather the fdark_warriors
$get_fdark_warriors = "select id, identity,
date_format(create_time, '%b %e %Y at %r') as fmt_fdark_warrior_create_time,
username, available from fdark_warrior where available = '0' order by create_time desc";
$get_fdark_warriors_res = mysql_query($get_fdark_warriors, $conn) or die(mysql_error());
if (mysql_num_rows($get_fdark_warriors_res) < 1) {
//there are no female dark warriors, so say so
$display_block .= "<table cellpadding=3 cellspacing=3 border=0 class=list_tables>
<tr>
<th><u>FEMALE DARK WARRIORS</u></th>";

//get number of players
$get_num_fdark_warriors = "select count(id) from fdark_warrior where available = '0'";
	$get_num_fdark_warriors_res = mysql_query($get_num_fdark_warriors, $conn)
		or die(mysql_error());
	$num_fdark_warriors = mysql_result($get_num_fdark_warriors_res, 0, 'count(id)');

if ($num_fdark_warriors<10){

         $num_fdark_warriors = "0".$num_fdark_warriors;

      }
  $display_block .= "
<th><u># OF PLAYERS: $num_fdark_warriors</u></th>
</tr>
<tr>
<td width=400><em>No Female Dark Warriors exist.</em></td></tr>";
} else {
//get number of players
$get_num_fdark_warriors = "select count(id) from fdark_warrior where available = '0'";
	$get_num_fdark_warriors_res = mysql_query($get_num_fdark_warriors, $conn)
		or die(mysql_error());
	$num_fdark_warriors = mysql_result($get_num_fdark_warriors_res, 0, 'count(id)');

//create the display string
$display_block .= "<table cellpadding=3 cellspacing=3 border=0 class=list_tables>
<tr>
<th><u>FEMALE DARK WARRIORS</u></th>";
if ($num_fdark_warriors<10){

         $num_fdark_warriors = "0".$num_fdark_warriors;

      }
  $display_block .= "
<th><u># OF PLAYERS: $num_fdark_warriors</u></th>
</tr>";

while ($fdark_warrior_info = mysql_fetch_array($get_fdark_warriors_res)) {
	$fdark_warrior_id= $fdark_warrior_info['id'];
	$fdark_warrior_identity = ucwords(strtolower($fdark_warrior_info['identity']));
	$fdark_warrior_create_time = $fdark_warrior_info['fmt_fdark_warrior_create_time'];
	$fdark_warrior_username = $fdark_warrior_info['username'];

	//add to display
	$display_block .= "
	<tr>
	<td width=400><a href=\"showprofile_fdark_warrior.php?id=$fdark_warrior_id\">
		<strong>$fdark_warrior_identity</strong></a><br>
		<em>Created on $fdark_warrior_create_time by</em> <strong>$fdark_warrior_username</strong></td>
		<td align=center> </td>
		</tr></table>";
	}
}	

//gather the male dark_warriors
$get_mdark_warriors = "select id, identity,
date_format(create_time, '%b %e %Y at %r') as fmt_mdark_warrior_create_time,
username, available from mdark_warrior where available = '0' order by create_time desc";
$get_mdark_warriors_res = mysql_query($get_mdark_warriors, $conn) or die(mysql_error());
if (mysql_num_rows($get_mdark_warriors_res) < 1) {
//there are no male dark warriors, so say so
$display_block .= "<table cellpadding=3 cellspacing=3 border=0 class=list_tables>
<tr>
<th><u>MALE DARK WARRIORS</u></th>";

//get number of players
$get_num_mdark_warriors = "select count(id) from mdark_warrior where available = '0'";
	$get_num_mdark_warriors_res = mysql_query($get_num_mdark_warriors, $conn)
		or die(mysql_error());
	$num_mdark_warriors = mysql_result($get_num_mdark_warriors_res, 0, 'count(id)');

if ($num_mdark_warriors<10){

         $num_mdark_warriors = "0".$num_mdark_warriors;

      }
  $display_block .= "
<th><u># OF PLAYERS: $num_mdark_warriors</u></th>
</tr>
<tr>
<td width=400><em>No Male Dark Warriors exist.</em></td></tr>";
} else {
//get number of players
$get_num_mdark_warriors = "select count(id) from mdark_warrior where available = '0'";
	$get_num_mdark_warriors_res = mysql_query($get_num_mdark_warriors, $conn)
		or die(mysql_error());
	$num_mdark_warriors = mysql_result($get_num_mdark_warriors_res, 0, 'count(id)');

//create the display string
$display_block .= "<table cellpadding=3 cellspacing=3 border=0 class=list_tables>
<tr>
<th><u>MALE DARK WARRIORS</u></th>";
if ($num_mdark_warriors<10){

         $num_mdark_warriors = "0".$num_mdark_warriors;

      }
  $display_block .= "
<th><u># OF PLAYERS: $num_mdark_warriors</u></th>
</tr>";

while ($mdark_warrior_info = mysql_fetch_array($get_mdark_warriors_res)) {
	$mdark_warrior_id= $mdark_warrior_info['id'];
	$mdark_warrior_identity = ucwords(strtolower($mdark_warrior_info['identity']));
	$mdark_warrior_create_time = $mdark_warrior_info['fmt_mdark_warrior_create_time'];
	$mdark_warrior_username = $mdark_warrior_info['username'];

	//add to display
	$display_block .= "
	<tr>
	<td width=400><a href=\"showprofile_mdark_warrior.php?id=$mdark_warrior_id\">
		<strong>$mdark_warrior_identity</strong></a><br>
		<em>Created on $mdark_warrior_create_time by</em> <strong>$mdark_warrior_username</strong></td>
		<td align=center> </td>
		</tr>";
	}
}	

	//close up the table
	$display_block .= "</table></td></tr></table>";
?>
<html>
<head>
<title>Sailor Moon RPG - Characters</title>
<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css); 
/*]]>*/
</style>
</head>
<body>
<!-- HEADER -->
<h1 class="logo">Sailor Moon RPG</h1>
<!-- /HEADER -->
<?php include("topnav.php"); ?>
<div id="main">
<?php include("includes/log.php"); ?>
<?php include("mainnav.php"); ?>
<h1>Characters In Sailor Moon RPG</h1>
<h3>Would you like to <a href="creationform.php">create a character</a>?</h3>
<?php print $display_block; ?>
</div>
<?php include("bottomnav.php"); ?><!-- FOOTER -->
<!-- FOOTER -->
<div id="footer_wrapper">
<div id="footer">
<p>Sailor Moon and all characters
are<br /> 
trademarks of Naoko Takeuchi.</p>
<p>Copyright © 2009 Liz Kula. All rights reserved.<br />
A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p>
<div id="foot-nav">
<ul>
<li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>
</ul>
</div>
</div>
</div>
<!-- /FOOTER -->
</body>
</html>

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.