lucy Posted August 3, 2009 Share Posted August 3, 2009 I am trying to write a blog for a website. I have written the data entry in PHP and HTML and also have written a data retrival in PHP. The problem is, the data retrival is not formated very well, i.e. it is only text, i cant change the colour, size or anything of it in the PHP file. Could someone please advise me how i can include the php file in the HTML file and then format the output via HTML. Below is my PHP file for data retrival which has a little formatting: <? $user="n-web53-blogger"; //specially created username $password="password"; $database="web53-blog"; //connect to the database $con = mysql_connect("localhost",$user,$password) or die ('Could not connect: ' . mysql_error()); //select the database mysql_select_db($database, $con); // query to select all records and convert to result $query=mysql_query("SELECT * FROM table1"); while ($row = mysql_fetch_array($query)) { $title = $row["title"]; $date = $row["date"]; $message = $row["message"]; $author = $row["author"]; //print results echo $title."<br> "; echo $date."<br> "; echo $message."<br> "; echo $author."<br> "; echo "----------------------------------------"; echo " <br>"; } //close connection mysql_close(); ?> Please can someone help me in formatting the output via HTML Thanks, Lucy Link to comment https://forums.phpfreaks.com/topic/168642-format-output-of-mysql-in-html/ Share on other sites More sharing options...
wildteen88 Posted August 3, 2009 Share Posted August 3, 2009 You just need to wrap your variables in HTML tags, eg echo "<h1>$title</h1>"; echo "<p>Posted on $date by <b>$author</b></p>"; echo "<p>$message</p>"; That some basic styling. To apply more you'd use CSS. Link to comment https://forums.phpfreaks.com/topic/168642-format-output-of-mysql-in-html/#findComment-889785 Share on other sites More sharing options...
lucy Posted August 3, 2009 Author Share Posted August 3, 2009 thanks a lot that was very obvious once explained!! how can i use a style sheet in the php? can i simply do the same thing i would do to use a style sheet in a HTML file? thanks, Lucy Link to comment https://forums.phpfreaks.com/topic/168642-format-output-of-mysql-in-html/#findComment-890115 Share on other sites More sharing options...
wildteen88 Posted August 3, 2009 Share Posted August 3, 2009 Yes. Link to comment https://forums.phpfreaks.com/topic/168642-format-output-of-mysql-in-html/#findComment-890158 Share on other sites More sharing options...
haku Posted August 3, 2009 Share Posted August 3, 2009 The process is basically like this: PHP -> HTML <- CSS Php outputs the HTML. You use CSS to act upon that HTML. The CSS doesn't do anything to the php (it cant - php isn't a 'thing' its more of an 'action', to give a bit of a metaphor.) Link to comment https://forums.phpfreaks.com/topic/168642-format-output-of-mysql-in-html/#findComment-890166 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.