December 18, 200817 yr Hey everyone, At the moment I'm using a script on my site which allows me to post news on the main page. Nothing special - I enter the name of the news, and the text on the admin page and it will show that ( and the date ) on the mainpage. But now I want more : I'd like to have a link at the bottom of each news which opens a pop-up window for comments. I know this could be done with a CMS, which creates new HTML pages, but that's too much, everything I want is a new page to be created and new tables in my database, each time when a news is posted. Do you understand what I mean ? Creation of a news = Creation of a new page ( comment pop-up ) + Creation of new table for that page So.. how do I do that ? Please help me it's really very important. And I really need this !! If you need more information about what I want to do, or if you don't understand it, please tell me Regards, Revs.
December 20, 200817 yr I just don't see why you would want a new table for each page... that's a mightily wasteful database design! There are proven patterns for this kind of thing already, and none of them ever create new tables per page. You shouldn't need to either. I don't fully understand what you're intention is to be honest. Perhaps an example of how you imagine the process would work step-by-step would help: start at the point a new news entry is submitted and go right through in detail until the point someone views the news entry.
December 20, 200817 yr Author Okay look : A news is posted on the mainpage. The data from that news is in one of the tables in the database. And at the bottom of each news, there's a like called "Comments" which opens a pop-up window and allows anyone to post a comment on that news. The thing is that I can't use the same pop-up window for each news, otherwise all news would have the same comments ( if someone would send a comment in News #2, this comment would also appear in the pop-up window of News #8, you see what I mean ? ). So I need something that creates new pages each time a news is sent, and this page will be used as a pop-up window for the comments. I thought it needs to create new tables in the DB, because each comment page ( which are pop-ups ) have to be saved in a new table. Here's a shema : => News is posted from Admin Section => New page is created which will be used as a pop-up window for comments => + new tables are created for that pop-up window That means it would create a table for that comment page in the DB for example called "commentsnews1" and all the comments for the News #1 would be saved in that table. Then another news is sent on the page, and automatically a new page is created ( used as a pop-up window for comments ), called "news-comments-2.php" ( and the pop-up will load news-comments-1.php ) and all the comments for News #2 would be saved in the table called "commentsnews2". Understand ?
December 20, 200817 yr Right see: Personally, I'd assign each news article/entry its own ID (e.g. starting at 1 for the first article/entry). The database would have a table like this: Name: news Fields: id (UNSIGNED INT, autoincrement, primary key); title (VARCHAR(256)); body (TEXT) You'll almost certainly want other fields in there too. Now you'll create a page like news.php which can pull each article from that table. For example, news.php?id=1 retrieves and displays the first news post ever made. You can tidy these URLs up with mod_rewrite or similar if you want later. On the page itself, you'll put a link to an addcomment.php page which takes an id query parameter which is the id of the news article for which a comment is being made, like this: addcomment.php?id=1 to add a new comment for the first article. When posted back to the server, this page will also include the same article ID which will be posted as news_id into this second table: Name: comments Fields: id (UNSIGNED INT, autoincrement, primary key); news_id (UNSIGNED INT); comment (TEXT) where the 'news_id' field links to the 'id' field in the news table. Comments can now be retrieved on a per-article basis by "SELECT * FROM comments WHERE news_id=$id" where $id is the ID of the news article. You can then display comments in the news.php page for the correct article. So I think you only need two tables and two or perhaps three PHP scripts for any number of news articles and comments, excluding the page for entering the news itself. Comprehend?
December 21, 200817 yr Author Well yeah, that's actually how I wanted to do it at the beginning, unfortunately I don't know how all that stuff with ?page=1 or ?id=1 works . I know the base and the process, I know how it works, but I don't know how to code it :'( . I'm not a pro a PHP.. Do you know where I can find a script like that ? Or tutorials ? I don't know what to search for in google, I need some keywords. But thanks mate .
December 21, 200817 yr If you want to do it yourself, you really need to learn PHP properly---which took me a good few weeks (and months for more advanced stuff) when I first started out. You can try Googling for "PHP tutorial" and see where that gets you. A good beginners PHP book will give you the most detailed and complete introduction however. You'll also need to be proficient with MySQL, so look into basic SQL features, database and table design etc. You may also find some existing CMS modules or blogs useful, as most provide a news page with optional comments. But in order to adapt those for your use, you'll probably need to understand the PHP that has been used. Alternatively, if you're a Web designer with no interest or no time for coding PHP, then you'll need to contract someone for the server side programming aspect A small project like this really shouldn't take more than a couple of days to design, code and test.
December 21, 200817 yr Author I know how to code PHP, I just don't know how to code things like that ! I think I know how it works, I've done something similar some time ago on my site, for a feedback form, see : http://www.manoelmanach.com/feedback.php . The pages.. it's always the same page but with different configs. I guess I'm gonna try it that way. Well, I'm gonna see what I can do, thanks for the time mate .
January 23, 200917 yr Sorry for the bump - but if you still need help on the ?id=# thing I can give you a hand.
January 24, 200917 yr Apologies for my arrogance but you can't say you know how to code php if you don't even understand query strings. All you have to do is make the news link go to: page.php?newsid=1 then put the following on page.php: <?php //connect to your database if(isset($_GET['newsid'])){ $newsid = $_GET['newsid']; mysql_query("SELECT * from table WHERE id='$newsid' "); //output news } ?> Hope that helps but again, I think you need to go back to basics as data methods (get/post) are pretty much the first things you need to know.
January 25, 200917 yr First you need to set the variable it using $_GET. eg. If I wanted to use "page" for the variable like index.php?page=1 I would use this. What it does exactly, is it checks if the variable in the URL is set, if it is set then it sets the page variable to whatever you had in the URL. If it isn't set in the URL it automatically sets it to "home". $page = isset($_GET['page']) ? $_GET['page'] : "home"; Then you can use that variable to dynamically show content based on the variable you have in the URL. The way I do it is I set a function, which calls for the page "$page.php" in the "content" folder. If it exists it includes the file, if it doesn't exist it shows a 404 page. My final code is this: $page = isset($_GET['page']) ? $_GET['page'] : "home"; function show_content($page){ $file = file_exists("content/$page.php") ? "content/$page.php" : "content/404.php"; require_once($file); } And to call it all I have to do is place "show_content($page)" wherever I want it to show up, and then whenever I go to "www.example.com/index.php?page=example" it would look for "www.example.com/content/example.php" and if it can't find it, it would show "www.example.com/content/404.php", BUT if I went to "www.example.com/index.php" it would show "www.example.com/content/home.php". It shouldn't take you too much to modify that code to suit your needs. Good luck! EDIT: I might eventually make this into a proper tutorial, lol.
January 29, 200917 yr Author Okay that's really strange :S Well I just asked if you could give me your MSN !
January 29, 200917 yr Ok, I don't usually add people I don't know, but I'll send you my address for the sake of helpin you out a bit if I can (lol).
Create an account or sign in to comment