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
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");
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";
?>

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.