surfwtw Posted July 14, 2011 Share Posted July 14, 2011 I have a form on my website where people can write articles. The form submits all the info into the database just fine. Below is what I want to do, but can't figure out. 1) Have a page that list the title of the articles in order from newest to oldest 2) I would like the output on this list to be links which go to a page that displays the article. Thanks Todd Quote Link to comment https://forums.phpfreaks.com/topic/242025-display-articles-stored-in-mysql-on-a-page-with-unique-url-and-a-link/ Share on other sites More sharing options...
requinix Posted July 14, 2011 Share Posted July 14, 2011 1. If it submits to the database "just fine" then you must know how to run SQL queries. So... run a SELECT query and use mysql_fetch_*() to get sequential rows from it. 2. Uh, sure. You can do that when you're printing the article titles. Did you make that form yourself? Or where did it come from? Quote Link to comment https://forums.phpfreaks.com/topic/242025-display-articles-stored-in-mysql-on-a-page-with-unique-url-and-a-link/#findComment-1242903 Share on other sites More sharing options...
surfwtw Posted July 15, 2011 Author Share Posted July 15, 2011 I'm really new to php and mysql but I have obsessed over building my site and learned quite a bit over the last month. I have a query where it displays the data in descending order, but I am not familiar with the print function. Here is what I have so far and it displays the article in order. There are more fields but for the link page I only want to display the title and the author. <?php // connect to your MySQL database here require_once "connect_to_mysql.php"; // Build the sql command string $sqlCommand = "SELECT * FROM articles ORDER BY date DESC LIMIT 10",; // Execute the query here now $query = mysql_query($sqlCommand) or die (mysql_error()); // Output the data here using a while loop, the loop will return all members while ($row = mysql_fetch_array($query)) { // Gather all $row values into local variables for easier usage in output $title = $row["title"]; $author = $row["author"]; $description = $row["description"]; // echo the output to browser echo "$title by - $author <hr />"; } // Free the result set if it is large mysql_free_result($query); mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/242025-display-articles-stored-in-mysql-on-a-page-with-unique-url-and-a-link/#findComment-1242909 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.