I would like to do something rather complicated for a type of classifieds site.

Basically, after a user creates a post in a certain category, that category is added to an SQL table. Let's assume the category is called "Books."
I want the title of the user's post to be posted in the "Books" section, along with all other posts in this category. Then, when someone clicks on the title of the post, its actual content is displayed in a different page (pretty much like Craigslist, but my site will differ in many other ways). How do I go about creating each page?
For the first page with the titles, I was thinking about doing:
$query = mysql_query("SELECT * FROM posts WHERE section='Books'")
or die(mysql_error());
and then somehow echoing the title for each row that meets this criterion. How can I do this?

I'd also appreciate any advice for the site at large.
Thanks a lot. And let me know if I'm not being clear I'll explain in more detail

Just to clarify, this is a sample of a first page I have in mind http://toronto.craigslist.ca/bar/ (all the titles of posts in the "barter" category are posted on this page)

Try like this:

$query = mysql_query("SELECT * FROM posts WHERE section='Books'")

while ($row = mysqli_fetch_assoc($query)){
printf($row['title']);
}

Okay.. As Catherine says would print out the title, however, to address your other question about displaying the books on a separate page:

1. Make sure your table consist a primary key (book_id)
2. Query the Book title, as well as the book_id
3. Create a new script (page) that selects all the information about this book, from the ID e.g.:
www.bookstore.com/books.php?id=1

<?php
   $id = $_GET['id'];
   // SELECT * FROM books WHERE book_id='$id';
?>

Pretty much done :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.