Jump to content

Display articles stored in Mysql on a page with unique url and a link


surfwtw

Recommended Posts

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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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();

?>

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.