boogiewoogie Posted July 5, 2011 Share Posted July 5, 2011 I have a website with a newspage that shows "news" from a mysql database. I would want to make it possible to click the headline of each item, so you can see it on it's own, and that you could add a Facebook LIKE button for each separate piece of news. Any suggestions on how I can do it? I suppose it somehow has to generate a subpage for each news item? As it is now, if I make a LIKE button, it just likes the main newspage. Kind of like a blog page, where you can LIKE each entry separately. Quote Link to comment https://forums.phpfreaks.com/topic/241115-website-newspage-php-each-item-openable-separately/ Share on other sites More sharing options...
boogiewoogie Posted July 5, 2011 Author Share Posted July 5, 2011 Now I simply show the new like this // get the info from the db $sql = "SELECT newsid, publishtime, newstitle, newstext FROM news ORDER BY `newsid` DESC LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data // echo $list['id'] . " : " . $list['number'] . "<br />"; echo '<center>'; echo '<b>'; echo $list['newstitle']; echo '</b>'; echo '</center>'; echo '<br />'; echo 'Posted at: '; echo $list['publishtime']; echo '<hr />'; echo nl2br($list['newstext']); echo '<br /><br />'; } //end while So basically, I would like to have a link after each item that you can click to open the news article on a subpage, or what it's called. Quote Link to comment https://forums.phpfreaks.com/topic/241115-website-newspage-php-each-item-openable-separately/#findComment-1238461 Share on other sites More sharing options...
boogiewoogie Posted July 5, 2011 Author Share Posted July 5, 2011 I can't really understand where to put what, how to make the page readable by using the "?id=1" etc. Could I also make the headlines clickable then by making a hyperlink pointing to that link? For example <a href="news.php?id=1">First piece of news</a> <a href="news.php?id=2">Second piece of news</a> Quote Link to comment https://forums.phpfreaks.com/topic/241115-website-newspage-php-each-item-openable-separately/#findComment-1238489 Share on other sites More sharing options...
TeNDoLLA Posted July 5, 2011 Share Posted July 5, 2011 Yes you could. Quote Link to comment https://forums.phpfreaks.com/topic/241115-website-newspage-php-each-item-openable-separately/#findComment-1238492 Share on other sites More sharing options...
boogiewoogie Posted July 5, 2011 Author Share Posted July 5, 2011 Thanks for the info. I am still quite lost though. Could someone give the basics of how to get the necessary stuff into the page? I only now read about "query strings" and I suppose that's how it works, but how to get it all to work. I will post here the full basic news page I have, with the sections not relevant here removed <?php require 'config.inc.php'; require 'functions.php'; /////////// // Head: // /////////// REMOVED /////////// // Body: // /////////// REMOVED // Center division of page: //Main text: echo "\n\t<div id=\"main-div\" class=\"news\">"; // database connection info $conn = connect_db() or error_message(); // get the info from the db $sql = "SELECT newsid, publishtime, newstitle, newstext FROM news ORDER BY `newsid` DESC"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data // echo $list['id'] . " : " . $list['number'] . "<br />"; echo '<center>'; echo '<b>'; echo $list['newstitle']; echo '</b>'; echo '</center>'; echo '<br />'; echo 'Posted at: '; echo $list['publishtime']; echo '<hr />'; echo nl2br($list['newstext']); echo '<br /><br />'; } //end while ////////////////////////// // Close body and html: // ////////////////////////// echo "\n</body>"; echo "\n</html>"; //////////////// // Functions: // //////////////// // Here you can keep functions you only need for this page ?> Could someone show where to add what? Quote Link to comment https://forums.phpfreaks.com/topic/241115-website-newspage-php-each-item-openable-separately/#findComment-1238530 Share on other sites More sharing options...
TeNDoLLA Posted July 5, 2011 Share Posted July 5, 2011 // You would add this line to inside the loop u echo all the news info: echo '<a href="somepage.php?news_id=' . $list['newsid'] .'"> Click to do somethin to this particular news </a>'; // Then in somepage.php OR in the same page or any url u want to define, you would check against // also validate with intval that the id will be int and bigger than zero if (isset($_GET['news_id']) && intval($_GET['news_id']) > 0) { $clickedId = $_GET['news_id'] // then do something with the chosen news id ... } Quote Link to comment https://forums.phpfreaks.com/topic/241115-website-newspage-php-each-item-openable-separately/#findComment-1238550 Share on other sites More sharing options...
boogiewoogie Posted July 5, 2011 Author Share Posted July 5, 2011 Great! Thanks a lot. I'm getting somewhere. Still, when I open the "direct link" right now, it still shows me the full base page Quote Link to comment https://forums.phpfreaks.com/topic/241115-website-newspage-php-each-item-openable-separately/#findComment-1238558 Share on other sites More sharing options...
TeNDoLLA Posted July 5, 2011 Share Posted July 5, 2011 That depends if you use the same address in the link where you show the full page of news. Just change the filename and create new file that will show only the news that was clicked from the link. Or something similar. Quote Link to comment https://forums.phpfreaks.com/topic/241115-website-newspage-php-each-item-openable-separately/#findComment-1238561 Share on other sites More sharing options...
boogiewoogie Posted July 5, 2011 Author Share Posted July 5, 2011 You're a real life-saver I got it working preliminary! One more thing, any clues on how to make the "newstitle" row clickable to lead to the article? // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data // echo $list['id'] . " : " . $list['number'] . "<br />"; echo '<center>'; echo '<b>'; echo $list['newstitle']; echo '</b>'; echo '</center>'; echo '<br />'; echo 'Posted at: '; echo $list['publishtime']; echo '<hr />'; echo nl2br($list['newstext']); echo '<br /><br />'; if ($list['youtube'] != '') { echo $list['youtube']; } if ($list['youtube2'] != '') { echo '<br /><br />'; echo $list['youtube2']; } echo '<a href="topnews.php?newsid=' . $list['newsid'] .'"> Read More </a>'; } //end while Quote Link to comment https://forums.phpfreaks.com/topic/241115-website-newspage-php-each-item-openable-separately/#findComment-1238574 Share on other sites More sharing options...
boogiewoogie Posted July 5, 2011 Author Share Posted July 5, 2011 Oh, and one more thing Right now I have the Code: echo nl2br($list['newstext']); to show the new text on the main page. How can I limit it to a certain number of rows? I want to display the full news article on the subpage, but just a snippet on the main news page. Quote Link to comment https://forums.phpfreaks.com/topic/241115-website-newspage-php-each-item-openable-separately/#findComment-1238583 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.