Jump to content

displaying HTML in my string variable


webguync

Recommended Posts

apparently I am doing this wrong. I want my string results from a form that searches DB content to appear within HTML table, tr, td tags. I get the results fine, but the HTML part isn't appearing. How should I be doing this?

 

<?php

$string = '';

$result = mysql_query($sql);  /// This is the execution
if (mysql_num_rows($result) > 0){
  while($row = mysql_fetch_object($result)){
  echo "<table>";
  echo "<tr>";
    $string .= "<td>".$row->last_name."</td> ";
     $string .= "<td>".$row->first_name."</td>";
  $string .= "<td>".$row->employee_id."</td>";
   $string .= "<td>".$row->title."</b>";
      $string .= "<td>".$row->territory."</td>";
	   $string .= "<td>".$row->district."</td>";
	    $string .= "<td>".$row->Phase1A_Score."</td>";
	  		   $string .= "<td>".$row->Phase1B_Score."</td>";
			    $string .= "<td>".$row->Phase1_Average."</td>";
	   $string .= "<td>".$row->Phase1A_HS_Exam."</td>";
	   $string .= "<td>".$row->Phase1A_HS_Exam_RT."</td>";
	    $string .= "<td>".$row->Phase1B_HS_Exam."</td>";
	   $string .= "<td>".$row->Phase1B_HS_Exam_RT."</td>";
	    $string .= "<td>".$row->Class_Date."</td>";
		 $string .= "<td>".$row->Awards."</td>";
    $string .= "<br/>\n";
echo "</tr>";
echo "</table>";
  
  }

}else{

  $string = "No matches found!";

} 

echo $string;


?>

Link to comment
Share on other sites

I don't know for sure that I understand exactly what you're asking, but maybe this will help:

 

<?php

$string = "<table>";
$result = mysql_query($sql);

if (mysql_num_rows($result) > 0) {
    while($row = mysql_fetch_object($result)) {
	$string .= "<tr>";
    	        $string .= "<td>".$row->last_name."</td>";
    	        $string .= "<td>".$row->first_name."</td>";
	$string .= "<td>".$row->employee_id."</td>";
	$string .= "<td>".$row->title."</td>";
	$string .= "<td>".$row->territory."</td>";
	$string .= "<td>".$row->district."</td>";
	$string .= "<td>".$row->Phase1A_Score."</td>";
	$string .= "<td>".$row->Phase1B_Score."</td>";
	$string .= "<td>".$row->Phase1_Average."</td>";
	$string .= "<td>".$row->Phase1A_HS_Exam."</td>";
	$string .= "<td>".$row->Phase1A_HS_Exam_RT."</td>";
	$string .= "<td>".$row->Phase1B_HS_Exam."</td>";
	$string .= "<td>".$row->Phase1B_HS_Exam_RT."</td>";
	$string .= "<td>".$row->Class_Date."</td>";
	$string .= "<td>".$row->Awards."</td>";
    	        $string .= "</tr>";
}
$string .= "</table>";
} else {
$string = "No matches found!";
} 

echo $string;

?>

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.