Displaying query results in a table - table pushed down according to # of result

I’ve put some code up at http://brewhas.org/transactions.php and could use some help.

Basically, I’m allowing the user to input the fname and lname of a player, and retrieving the transactions that match the player’s name and formatting those rows into an HTML table. That’s working, but the table appears to be pushed down a certain distance, and the distance appears to be related to the number of rows.

Say if you type in last name of ‘pujols’, the 10 rows are pushed down but still on the screen. Enter in a last name of ‘will’ and there are a lot more rows (using LIKE) so it’s really pushed down.

Also, I tried to add validation on the last name needing to be populated but when I hit that validation, I still get a large number of rows being returned (possibly due to the LIKE?).

Can anyone help sort this out? thanks

[php]<?php
include ‘config.php’;
include ‘opendb.php’;

					$fnamesearch = $_POST["fnamesearch"];
					$lnamesearch = $_POST["lnamesearch"];
					$fnamesearch=strtoupper($fnamesearch);
					$lnamesearch=strtoupper($lnamesearch);

					if ($_POST["lnamesearch"]== ""){

						echo "Please enter the last name.";
					}
					
					if ($_POST["fnamesearch"]== ""){

						$query = "SELECT * from BKL_TRANSACTIONS WHERE PLAYER_LNAME LIKE '$lnamesearch%'";
					}
					else {
						$query = "SELECT * from BKL_TRANSACTIONS WHERE((PLAYER_LNAME LIKE '$lnamesearch%')& (PLAYER_FNAME LIKE '$fnamesearch%'))";
					}

						$result = mysql_query($query);
					
					if (!$result)
					{
						die ("Could not query the database: <br />". mysql_error());
					} 
						echo "<table border=1 cellspacing=0 cellpadding=1 width='77%' align=center bordercolor=#666666>";
						echo "<tr bgcolor=#cccc99 class='style5'><th width='10%' class='style5'>Date</th>";
						echo "<th width='10%' class='style5'>Action</th>";
						echo "<th width='12%' class='style5'>From</th>";
						echo "<th width='12%' class='style5'>To</th>";
						echo "<th width='5%' class='style5'>Pos</th>";
						echo "<th width='18%' class='style5'>Name</th>";		
						echo "<th width='5%' class='style5'>Round</th></tr>";							
					
					while ($row = mysql_fetch_array($result))
					{
						echo "<tr>";
						echo "<td width='10%' class='style6'>".$row['TRANS_DT']."</td>";
						echo "<td width='10%' class='style6'>".$row['TRANS_ACTION']."</td>";
						echo "<td width='12%' class='style6'>".$row['FROM_OWNER']."</td>";
						echo "<td  width='12%' class='style6'>".$row['TO_OWNER']."</td>";
						echo "<td  width='5%' class='style6'>".$row['POSITION']."</td>";
						echo "<td  width='18%' class='style6'>".$row['PLAYER_FNAME']." ".$row['PLAYER_LNAME']."</td>";
						echo "<td  width='5%' class='style6'>".$row['DRAFT_RND']."</td></tr>";
						echo "<br/>";
					}
						echo "</table>";
					mysql_close($conn);
				?>[/php]

solved the validation problem.

now just focused on the display of the table and why it’s pushed down

Hi there,

Have you tried removing the
echo at the end of while loop?

that did help to shorten it up.

I also combined the first echo in the while loop (just echo tr) with the second (so

) but still am seeing (less but still some) white space before the results.
First Name: Last Name:
		<?php
				include 'config.php';
				include 'opendb.php';
					
					$fnamesearch = $_POST["fnamesearch"];
					$lnamesearch = $_POST["lnamesearch"];
					$fnamesearch=strtoupper($fnamesearch);
					$lnamesearch=strtoupper($lnamesearch);
					$fnamesearch=trim($fnamesearch);
					$lnamesearch=trim($lnamesearch);
					//This checks to see if there is a page number. If not, it will set it to page 1 			
					if (!(isset($pagenum))) 
						{ 
							$pagenum = 1; 
						} 
					if (strlen($lnamesearch)<2)
						{
							echo "<p class='style7'>Please enter at least 2 letters of the last name.</p>";
							exit;
						}
					else 
						{
							$query = "SELECT * from BKL_TRANSACTIONS WHERE((PLAYER_LNAME LIKE '$lnamesearch%')& (PLAYER_FNAME LIKE '$fnamesearch%'))";
						}
				
					$result = mysql_query($query) or die ("Could not execute the query");
					//Here we count the number of results 
					$numrows=mysql_num_rows($result);
					echo "Number of rows:".$numrows;
					//This is the number of results displayed per page 
					$page_rows=25;
					//This tells us the page number of our last page 
					$last=CEIL($numrows/$page_rows);
					//this makes sure the page number isn't below one, or more than our maximum pages 
					if ($pagenum < 1)
						{
							$pagenum = 1;
						}
					elseif ($pagenum > $last)
						{
							$pagenum = $last;
						}
					//This sets the range to display in our query 
					$max = 'limit ' .($pagenum - 1) * $page_rows.',' .$pagerows;
					
					echo "Number of pgs:".$last;
					
					if ($numrows == 0) 
						{
						  echo "<p class='style7'>Sorry, your search: &quot;".$fnamesearch." ".$lnamesearch."&quot; returned zero results.</p>";
						 }
					else
						{
									echo "<table border=1 cellspacing=0 cellpadding=1 width='77%' align=center bordercolor=#666666>";
									echo "<tr bgcolor=#cccc99 class='style5'><th width='10%' class='style5'>Date</th>";
									echo "<th width='10%' class='style5'>Action</th>";
									echo "<th width='12%' class='style5'>From</th>";
									echo "<th width='12%' class='style5'>To</th>";
									echo "<th width='5%' class='style5'>Pos</th>";
									echo "<th width='18%' class='style5'>Name</th>";		
									echo "<th width='5%' class='style5'>Round</th></tr>";							
	
								while ($row = mysql_fetch_array($result))
								{
									echo "<tr><td width='10%' class='style6'>".$row['TRANS_DT']."</td>";
									echo "<td width='10%' class='style6'>".$row['TRANS_ACTION']."</td>";
									echo "<td width='12%' class='style6'>".$row['FROM_OWNER']."</td>";
									echo "<td  width='12%' class='style6'>".$row['TO_OWNER']."</td>";
									echo "<td  width='5%' class='style6'>".$row['POSITION']."</td>";
									echo "<td  width='18%' class='style6'>".$row['PLAYER_FNAME']." ".$row['PLAYER_LNAME']."</td>";
									echo "<td  width='5%' class='style6'>".$row['DRAFT_RND']."</td></tr>";
								}
									echo "</table>";
									
									// This shows the user what page they are on, and the total number of pages

									echo " --Page $pagenum of $last-- <p>";
									
						}			
					mysql_free_result($result);	
					mysql_close($conn);
				?>

Thanks but never mind. I got it. In my form, I had a typo on the height and it was pushing everything down.

Thanks for helping me to look at what was there rather than what was missing.

Sponsor our Newsletter | Privacy Policy | Terms of Service