neogemima Posted April 18, 2009 Share Posted April 18, 2009 Hello, so here is my dilemma. I have managed, thanks to your help here on the forums to create a page that accepts input from users to create "News" postings to my website and get that news to display in order on the home page using a generic php file I named "recentnews.php". Now I would like to get each posting to link to its unique content, i.e. a page displaying the title and contents of that particular post. Right now, to get recentnews.php to post the articles I am using this for loop: $i = $num_rows; for($i = $num_rows; $i >= ($num_rows - 31); $i--) { $sql = "SELECT id, date, title FROM Newsposting WHERE id = $i"; $queryresult = mysqli_query($db, $sql); $rowresult = mysqli_fetch_array($queryresult, MYSQLI_ASSOC); //printf ("<u>(%s) %s</u>\n", $rowresult["date"], $rowresult["title"]); echo '<a href="article.php">'.$rowresult['date'].' '.$rowresult['title'].'</a>'; echo "<br>"; } I want only the most recent 31 posts to display. I know that "<a href="article.php">" is not correct. Anyone have any suggestions? The site is: www.biotechposting.com and these news posts can be seen on the home page, right now they are just tests with random titles. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/154687-solved-creating-a-php-generated-list-of-links-to-unique-pages/ Share on other sites More sharing options...
jackpf Posted April 18, 2009 Share Posted April 18, 2009 That's awfully long winded. Why not just use a while() loop and limit your query to 31 rows? Link to comment https://forums.phpfreaks.com/topic/154687-solved-creating-a-php-generated-list-of-links-to-unique-pages/#findComment-813427 Share on other sites More sharing options...
neogemima Posted April 18, 2009 Author Share Posted April 18, 2009 That's a good idea. I am new to PHP, so I imagine my code is a bit roundabout using code I am familiar with. Any thoughts on making each link connect to its own page? Link to comment https://forums.phpfreaks.com/topic/154687-solved-creating-a-php-generated-list-of-links-to-unique-pages/#findComment-813450 Share on other sites More sharing options...
jackpf Posted April 18, 2009 Share Posted April 18, 2009 Something like this? $id = $rowresult['id']; echo '<a href="article.php?id='.$id.'">Article</a>'; //and then on the article page $id = $_GET['id']; //and so on.... Link to comment https://forums.phpfreaks.com/topic/154687-solved-creating-a-php-generated-list-of-links-to-unique-pages/#findComment-813468 Share on other sites More sharing options...
neogemima Posted April 19, 2009 Author Share Posted April 19, 2009 Worked like a charm, thank you. Link to comment https://forums.phpfreaks.com/topic/154687-solved-creating-a-php-generated-list-of-links-to-unique-pages/#findComment-813539 Share on other sites More sharing options...
jackpf Posted April 19, 2009 Share Posted April 19, 2009 Spiffing. Link to comment https://forums.phpfreaks.com/topic/154687-solved-creating-a-php-generated-list-of-links-to-unique-pages/#findComment-813700 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.