473,503 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to display recent posts from database into php homepage?

36 New Member
I want is to display post details ( title, description, username ) on my home page within a div tag in a proper format like all websites have . The problem im facing is that all the data from database are getting displayed as a plain text , one below the other . I am new to php , so please guide me to achieve the result . Here is my code .

I want to display in this tag :
Expand|Select|Wrap|Line Numbers
  1. <div id='display'>
  2.      <h3 class='name'></h3>
  3.      <h1 class='title' ></h1>
  4.      <p class='desc'></p>
  5.      <p class='cat'></p>
  6.      <p class='sub_cat'></p>   
  7. </div>
And my php code is :
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.      $row="";
  3.  
  4.      $link = mysql_connect("localhost","username","password");
  5.      mysql_select_db("database");
  6.      $query = "SELECT * from posts ORDER by post_id DESC limit 0,5";
  7.      $result = mysql_query($query);
  8.      $result = mysql_query($query) or die("Query to get blah  failed with error: ".mysql_error());
  9.  
  10.      while($row = mysql_fetch_array($result)) { 
  11.      echo "<div id='display'>";
  12.      echo "<h3 class='name'>".$row['username']."</h3>";
  13.      echo "<h1 class='title' >".$row['post_title']."</h1>";
  14.      echo "<p class='cat'>".$row['cat']."</p>";
  15.      echo "<p class='sub_cat'>".$row['sub_cat']."</p>";
  16.      echo "<p class='desc'>".$row['post_desc']."</p>";
  17.      echo "</div>";
  18.     } 
  19.  
  20. mysql_close($link);
  21. ?>
  22.  
I need the title to be a link . Thanks in advance .
Dec 3 '12 #1
1 2546
Rabbit
12,516 Recognized Expert Moderator MVP
What you have there should work. If you are getting just plain text, you probably don't have your styles set up correctly. Just because it's between certain elements doesn't mean it's going to look the way you want. You need to set up the styles correctly as well. You should post what the HTML looks like to the client to make sure that it's outputting the correct HTML.

As for your second question, we only allow one question per thread in this forum. Please create a new thread for it.
Dec 3 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2385
by: Wayne Wengert | last post by:
I am trying to build an ASP.NET application which includes the capability to allow users to save pictures to a SQL Server 2000 database table and then later to display selected photos (usually JPG...
0
1007
by: Hatebreed | last post by:
i have been having trouble gathering the x most recent posts with their author. if somone could help me out with a quick snippet or some other type of help i would be greatful for life. php -...
3
5224
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
4
6922
by: neena | last post by:
how to display values from database tables without using datagrid control in C# .net.I want to search the values from database & the search results to be shown as rows in the web form,without the use...
14
11849
by: rolfejr | last post by:
I am trying to display a PDF in the users browser that is pulled from a binary field in our database, and keep that PDF from caching on the client computer. I can successfully pull the PDF and...
1
1041
by: pagoto123 | last post by:
how i display my database items in my web site.... pls help me ... i want to have a textbox and a search button and when i hit the search i want it to go through the database find if the director...
48
41348
by: mirianCalin | last post by:
i am doing a site for appliance center.. i need to display all the products that the company offers, but my problem is that i cant display ALL the images in my database.. the first entry on the...
1
1685
by: ganesh22 | last post by:
Hi, my requriment is i want to display data from database in ms.word? Iam using asp.net with C# bcoz iam inserting resume in sqlserver, so i want to display that resume in word
7
6935
by: ieda | last post by:
I want to display information when value in listbox selected. Below is my code:- This code to get value option in listbox <? $query = "select courseTitle from training where startDate > NOW()...
5
2526
by: SafaaDalloul | last post by:
Please I want know How I can Display Image from database randomly when the web page refresh in Asp.net by C# code
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.