aaricwon Posted February 12, 2008 Share Posted February 12, 2008 I am new here but learning fast... Check it out here:http://www.bjjnews.org/TUF/fighterdb/search.php?search=A You will see what I am talking about. How can I get this aligned and looking good? <?php // connect to the mysql database server. mysql_connect ($dbhost, $dbusername, $dbuserpass); //select the database mysql_select_db($dbname) or die('Cannot select database'); //search variable = data in search box or url if(isset($_GET['search'])) { $search = $_GET['search']; } //trim whitespace from variable $search = trim($search); $search = preg_replace('/\s+/', ' ', $search); //seperate multiple keywords into array space delimited $keywords = explode(" ", $search); //Clean empty arrays so they don't get every row as result $keywords = array_diff($keywords, array("")); //Set the MySQL query if ($search == NULL or $search == '%'){ } else { for ($i=0; $i<count($keywords); $i++) { $query = "SELECT * FROM registering_fighters " . "WHERE id LIKE '%".$keywords[$i]."%'". " OR field_1 LIKE '%".$keywords[$i]."%'" . " OR field_2 LIKE '%".$keywords[$i]."%'" . " OR field_13 LIKE '%".$keywords[$i]."%'" . " OR field_7 LIKE '%".$keywords[$i]."%'" . " OR field_8 LIKE '%".$keywords[$i]."%'" . " ORDER BY field_2"; } //Store the results in a variable or die if query fails $result = mysql_query($query) or die(mysql_error()); } if (isset ($_GET['id'])) { $id = $_GET['id']; } if ($search == NULL or $search == '%'){ } else { //Count the rows retrived $count = mysql_num_rows($result); } echo "<html>"; echo "<head>"; echo "<title>Tuff-N-Uff Fighter Database</title>"; echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />"; echo "</head>"; echo "<body onLoad=\"self.focus();document.searchform.search.focus()\">"; echo "<center>"; echo "<br /><form name=\"searchform\" method=\"GET\" action=\"search.php\">"; echo "<input type=\"text\" name=\"search\" size=\"15\" TABINDEX=\"1\" />"; echo " <input type=\"submit\" value=\"Search\" />"; echo "</form>"; //If search variable is null do nothing, else print it. if ($search == NULL) { } else { echo "You searched for <b><FONT COLOR=\"blue\">"; foreach($keywords as $value) { print "$value "; } echo "</font></b>"; } echo "<p> </p><br />"; echo "</center>"; //If users doesn't enter anything into search box tell them to. if ($search == NULL){ echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br /></center>"; } elseif ($search == '%'){ echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br /></center>"; //If no results are returned print it } elseif ($count <= 0){ echo "<center><b><FONT COLOR=\"red\">Your query returned no results from the database.</font></b><br /></center>"; //ELSE print the data in a table } else { //Colors for alternation of row color on results table $color1 = "#d5d5d5"; $color2 = "#e5e5e5"; //While there are rows, print it. while($row = mysql_fetch_array($result)) { //Row color alternates for each row $row_color = ($row_count % 2) ? $color1 : $color2; //table background color = row_color variable echo "<center><table bgcolor=".$row_color." width=\"750\">"; echo "<tr>"; echo "<td><b>".$row['field_1']." ".$row['field_2']."</b></td>"; echo "<td>".$row['field_13']."</td>"; echo "<td>".$row['field_7']."</td>"; echo "<td>".$row['field_8']."</td>"; echo "<td><b><a href='fighter_bio.php?id=".$row['id']."'> VIEW PROFILE</b></a></td>"; echo "</tr>"; echo "</table></center>"; $row_count++; //end while } //end if } echo "</body>"; echo "</html>"; if ($search == NULL or $search == '%') { } else { //clear memory mysql_free_result($result); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/90771-what-is-wrong-with-my-formattingalignment-please-help/ Share on other sites More sharing options...
PHP Monkeh Posted February 12, 2008 Share Posted February 12, 2008 Although you're echo-ing it via PHP I'd say this is more of a HTML question. As for an answer, I think it'll be because you haven't set any widths for your table cells. Table width is 750, you've got 5 columns so set the widths of each to 150, like so: echo "<center><table bgcolor=".$row_color." width=\"750\">"; echo "<tr>"; echo "<td width=\"150\"><b>".$row['field_1']." ".$row['field_2']."</b></td>"; echo "<td width=\"150\">".$row['field_13']."</td>"; echo "<td width=\"150\">".$row['field_7']."</td>"; echo "<td width=\"150\">".$row['field_8']."</td>"; echo "<td width=\"150\"><b><a href='fighter_bio.php?id=".$row['id']."'> VIEW PROFILE</b></a></td>"; echo "</tr>"; echo "</table></center>"; Obviously you might want to make some columns wider than others, but that might sort out your problem. Quote Link to comment https://forums.phpfreaks.com/topic/90771-what-is-wrong-with-my-formattingalignment-please-help/#findComment-465291 Share on other sites More sharing options...
thebadbad Posted February 12, 2008 Share Posted February 12, 2008 If you use the table right, it will all line up. You have a table for each row; instead use only one table, and then have a single row (<tr>) in your PHP loop. Quote Link to comment https://forums.phpfreaks.com/topic/90771-what-is-wrong-with-my-formattingalignment-please-help/#findComment-465301 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.