Jump to content

retrieving data from MySQL table


thunderbox

Recommended Posts

hey guys.. im having a little trouble getting data from my database to the script... i realy dont know how to do it..

im making a very simple blog site, which is more like a bulletin site in which people can leave comments but only after they register

i have been successful in getting both the user to register and getting the blog they post into the database, but i don't know how to display the database on the main page..

how would i do this?

btw. my database has 4 fields that need displaying

username, date, title and content.. and im not sure if i should put the unique ID in there.. so if someone could figure out how to put those details into variables.

i had a small idea of how to do this but im not sure on how to do it for every post, i think it is done through looping but i am not sure.

thanks for your help, im a complete newbie (4 days of programming)
Link to comment
Share on other sites

You can do this in a couple of ways.  I would probably issue a select command "select * from blog_entries where..." and then loop through the entries in php:

$query = "select * from blog_entries where...";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
  //html format code here
}

Anyone have a more eloquent solution?
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.