Jump to content

Trouble with getting PHP to display a table and colspan (found a work around)


migroo

Recommended Posts

I found a workaround so it is working now. All I did was put the about class on the first div tag that is inside the <tr> tag. Now it looks a little different but it works.Okay I have a table that is being built using some php. What I am trying to do is display a data from a database (ID | NAME | AGE | DATE OF BIRTH | DATE OF DEATH) and when you click on a row it is supposed to pop up with some some input fields so I am using a <th> tag so I can do a colspan for all five columns. The problem it is acts like I am not spanning any of the columns.Here is my code:

<?php$dbhost = "localhost";$dbuser = "my username";$dbpass = "my password";$dbname = "User_".$_GET['db'];$dtname = $_GET['dt'];$refine = $_GET['refine'];$search = "%";$search .= $_GET['search'];$search .= "%";$by = $_GET['by'];$x=0;$qf='"';$qh="'";//-^^^^^^^^^^^^^^^^^^^^^^- All variables ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ are up there! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------------------------------------	//Connect to MySQL Servermysql_connect($dbhost, $dbuser, $dbpass);	//Select Databasemysql_select_db($dbname) or die(mysql_error());	// Retrieve data from Query Stringif($refine == ""){$query = "SELECT * FROM $dt ORDER BY ID ASC";}if($refine == "obits"){$query = "SELECT * FROM $dt WHERE $by LIKE '$search' ORDER BY $by ASC";}	//Execute query$qry_result = mysql_query($query) or die(mysql_error());if($dt=="people"){	//Build Result String		$display_string = "";		$display_string .= "	 		 Search: <input type='text' tabindex='1' id='search' value='".$_GET['search']."'/> By: <select id='by' tabindex='3'>															   <option value='lname'>Last Name</option>															   <option value='fname'>First Name</option>															   <option value='age'>Age</option>			 </select>			 			 <input type='button' tabindex='2' onclick='search1()' 										  value='Search!'/>";		$display_string .= "<table class='people'>";		$display_string .= "<tr>";		$display_string .= '			 <td class="id">ID</td>			 <td class="name">NAME</td>			 <td class="age">AGE</td>			 <td class="dob">DATE OF BIRTH</td>			 <td class="dod">DATE OF DEATH</td>';		$display_string .= '</tr>';		// Insert a new row in the table for each person returned		while($row = mysql_fetch_array($qry_result)){		$display_string .= '		 <tr onclick='.$qh.'setVisibility("sub'.$x.'", "inline");'.$qh.'>			 <td>'.$row['ID'].'</td>			 <td>'.$row['fname'].' '.$row['lname'].'</td>			 <td>'.$row['age'].'</td>			 <td>'.$row['dob'].'</td>			 <td>'.$row['dod'].'</td>		 </tr>		 <tr class="about" id="sub'.$x.'">			 <th colspan="5">			  <div style="background-color:grey;">				   <input type="text" />				   <br />				   <input type="text" />				   <br />				   <input type="text" />				   <br />				   <input type="text" />				   <br />				   <input type="text" />				   <br />				   <textarea>				   </textarea>			   			  </div>			 </th>		 </tr>';		 $x++;		}		$display_string .= "</table>";		$display_string .= '<input type="hidden" value="'.$x.'" name="sum"';		$display_string .= '<hr />';}echo $display_string;echo "The table is: ".$dt;echo " The database is: ".$db;echo " There are: ".$x." entries.";?>

Now every thing works just fine exept for:

<tr class="about" id="sub'.$x.'">			 <th colspan="5">			  <div style="background-color:grey;">				   <input type="text" />				   <br />				   <input type="text" />				   <br />				   <input type="text" />				   <br />				   <input type="text" />				   <br />				   <input type="text" />				   <br />				   <textarea>				   </textarea>			   			  </div>			 </th>		 </tr>';

It just won't span the columns like it should.Does any one know what is wrong with this?Also does anyone have some tips on formatting so my code is more readable?

Link to comment
Share on other sites

I have never used Dreamweaver I just have notepad++. I tried validating the code and I didn't get any errors it just won't display right. Is Dreamweaver worth the money?

Link to comment
Share on other sites

DW does have some nice features, but go check out the trial. For dealing with tables it could be a time saver because you can merge cells through the GUI rather than trying to read your long code and seeing where the colspans and rowspans are being applied.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...