pluto Posted August 7, 2009 Share Posted August 7, 2009 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 More sharing options...
mikesta707 Posted August 7, 2009 Share Posted August 7, 2009 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 https://forums.phpfreaks.com/topic/169255-solved-formatting-php-output/#findComment-893127 Share on other sites More sharing options...
pluto Posted August 7, 2009 Author Share Posted August 7, 2009 You are a total legend!! Thank you so very much Link to comment https://forums.phpfreaks.com/topic/169255-solved-formatting-php-output/#findComment-893136 Share on other sites More sharing options...
wildteen88 Posted August 7, 2009 Share Posted August 7, 2009 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 https://forums.phpfreaks.com/topic/169255-solved-formatting-php-output/#findComment-893138 Share on other sites More sharing options...
watsmyname Posted August 7, 2009 Share Posted August 7, 2009 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 https://forums.phpfreaks.com/topic/169255-solved-formatting-php-output/#findComment-893139 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.