Jump to content

[SOLVED] Formatting PHP output


pluto

Recommended Posts

Hi guys,

 

Me once again, I'm working with a PHP page, which the output I'd like to be formatted by a css file.  This is the code I have so far.

 

<?php
session_start();
require("con_mgr.php");
$chapSelect = $_POST['chapSelect'];
$_SESSION['wordArray']=$get_field;
$_SESSION['currentWord']=$value;

$result = mysql_query("SELECT GreekWord FROM WORD where Chapter >= $chapSelect");

$num_rows = mysql_num_rows($result);

$get_field = mysql_fetch_row($result);


foreach($get_field as $value)
{
	$display="<HTML>";
	$display.="<link rel=\"stylesheet\" type=\"text/css\" href=\"test.css\">";
	$display.="<div id=\"testWord\">";
	$display.="<?php echo $value; ?>";
	$display.="</div>";
	$display.="</HTML>";
}
echo($display);
//header("Location:http://localhost/SessionDemo/demo2.php");
?>

 

I have a css file called test.css which has a div section that formats the text as red, and makes the font quite big.  At least that's the plan.

 

I've tried everything I can think of, but it won't return anything at all.  And I'm not sure why it's not doing that.

 

Or ideally I'd like the variable to be passed to a HTML (or the value thereof, I'm thinking like a Java coder again!!!)

 

Any help would be awesome.

 

Thanks

 

Pluto

Link to comment
https://forums.phpfreaks.com/topic/169255-solved-formatting-php-output/
Share on other sites

there is a syntax error there. You don't need to echo PHP inside php tags

 

<?php
   session_start();
   require("con_mgr.php");
   $chapSelect = $_POST['chapSelect'];
   $_SESSION['wordArray']=$get_field;
   $_SESSION['currentWord']=$value;
   
   $result = mysql_query("SELECT GreekWord FROM WORD where Chapter >= $chapSelect");
   
   $num_rows = mysql_num_rows($result);
   
   $get_field = mysql_fetch_row($result);
   
   
   foreach($get_field as $value)
   {
      $display="<HTML>";
      $display.="<link rel=\"stylesheet\" type=\"text/css\" href=\"test.css\">";
      $display.="<div id=\"testWord\">";
      $display.="$value";
      $display.="</div>";
      $display.="</HTML>";
   }
   echo($display);
   //header("Location:http://localhost/SessionDemo/demo2.php");
?>

pluto You should note that the following highlighted lines

foreach($get_field as $value)

  {

      $display="<HTML>";

      $display.="<link rel=\"stylesheet\" type=\"text/css\" href=\"test.css\">";

      $display.="<div id=\"testWord\">";

      $display.="$value";

      $display.="</div>";

      $display.="</HTML>";

  }

 

Should be outside of your loop. Otherwise they will be defined more than once, which will cause invalid HTML.

nothing seems wrong in a code except that  $display.="<?php echo $value; ?>", you dont need php tag inside php tag and rest look below

 

<?php
foreach($get_field as $value)
   {
      $display="<HTML>";
      $display.="<link rel=\"stylesheet\" type=\"text/css\" href=\"test.css\">";
      $display.="<div id=\"testWord\">";
      $display.="<?php echo $value; ?>";
      $display.="</div>";
      $display.="</HTML>";
   }
?>

 

Why on earth you are putting <html> inside loop?

you should put it outside...do like this

<?php
echo "<HTML>";
echo "<link rel='stylesheet' type='text/css' href='test.css'>";
foreach($get_field as $value)
   {
      $display.="<div id=\"testWord\">";
      $display.=$value;
      $display.="</div>";
      
   }
echo "</HTML>";
?>

Archived

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

×
×
  • 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.