0

Hello,

I am having a problem displaying database query in a DIV.

I can display the data without issue using this code:

<?php 

if (isset ($_POST ['submitted'])) {
	
	include ('connect_php_projects.php');
	
	$category = $_POST ['category'];
	$criteria = $_POST ['criteria'];
	$data     = mysql_query ("SELECT * FROM discipline WHERE $category LIKE '%$criteria%'");
		
    
	
   	 while ($row = mysql_fetch_assoc ($data)) 
	
	{
	
		$id = $row ['id'];
		$name = $row ['name'];
		$title = $row ['title'];
		$division = $row ['division'];
		$date = date ("Y-m-d");
		$supervisor = $row ['supervisor'];
		$discipline = $row ['discipline'];
		$disciplinaryaction = $row ['disciplinaryaction'];
		$lastaction = $row ['lastaction'];
		$incidentdescription = $row ['incidentdescription'];
		$actionrequired = $row ['actionrequired'];
		

// Employee details and supervisor table
echo "<table border='3' table width='80%' align='center' cellpadding ='5px'>";
echo "<tr bgcolor = '#ffcc00'><td>";
echo "EMPLOYEE NAME:";
echo "<br><b>";
echo $row ['name'];
echo "</b></td><td>";
echo "TITLE:";
echo "<br><b>";
echo $row ['title'];
echo "</td><td>";


echo "DIVISION:";
echo "<br><b>";
echo $row ['division'];
echo "</b></td><td>";
echo "DATE:";
echo "<br><b>";
echo $row ['date'];
echo "</b></td></tr>";
echo "<br></<br>";
echo "<p></p>";
echo "<p></p>";

echo "<tr><td>";
echo "NAME / TITLE OF SUPERVISOR COMPLETING FORM:";
echo "<br><b>";
echo $row ['supervisor'];
echo "</b></td></tr>";



// DISCIPLINE table

echo "<table border='1' table width='80%' align='center' cellpadding ='5px'>";
echo "<tr valign = 'center'><td height='30px' bgcolor = '#9999FF'>";
echo "DISCIPLINARY ACTION";
echo "</td><tr>";
echo "<td><i>";
echo $row ['discipline'];
echo "</i></td></tr>";
echo "<tr></tr>";
echo "<p></p>";



// DATE AND TYPE OF LAST ACTION table

echo "<table border='1' table width='80%' align='center' cellpadding ='5px'>";
echo "<tr valign = 'center'><td height='30px' bgcolor = '#9999FF'>";
echo "DATE AND TYPE OF PREVIOUS ACTION";
echo "</td><tr>";
echo "<td>";
echo nl2br ($row ['lastaction']);
echo "</td></tr>";
echo "<tr></tr>";
echo "<p></p>";

		
	} //end of while loop
	
} //end of if statement 

echo "</table>";
?>

The problem arises when I try and use php inside divs. The reason I want to do this is so I can have an accordion effect with the name etc visible and when clicked on the remainder of the data slides down for viewing.

Here is some of the code I have used, any help would be gratefully received.

<div id="" class="row">				

<div class="cell1">EMPLOYEE NAME:<br /><?php  echo $row ['name'];?></div>
<div class="cell1">TITLE:<br /><?php  echo $row ['title'];?></div>
			
</div>
2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by diafol
0

OK, if you want to do it like that, just run the loop - all of it before the doctype declaration.

Instead of echoing everything out - simply place it into a string and echo that out in the appropriate place. Here's an example:

$string = "<table><thead><tr><th>head1</th><th>head2</th></tr></thead><tbody>";
while(...){
  $string .= "<tr><td>{$row['field1']}</td><td>{$row['field2']}</td></tr>";
}
$string .="</tbody></table>";

Then in the appropriate place:

<div id="...">
  <?php echo $string;?>
</div>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.