alejandro52 Posted May 24, 2007 Share Posted May 24, 2007 I want to create a simple dynamic page where when i click on a link to automatically create the page. What i mean.. I have some news that display by date, and because they will be updated every day i don't want to create a page for each one of these. So when the user goes to the index page of the news(where the news are displayed by date) and clicks on one, I want the php do all the job and create a new web page where it will add the hole text of the "new" the user selected in a page template.How do i do that? ??? Can i use the dreamweaver templates? Quote Link to comment https://forums.phpfreaks.com/topic/52776-newbie-dynamic-web-page-link/ Share on other sites More sharing options...
alejandro52 Posted May 24, 2007 Author Share Posted May 24, 2007 someone help? Quote Link to comment https://forums.phpfreaks.com/topic/52776-newbie-dynamic-web-page-link/#findComment-260597 Share on other sites More sharing options...
Dragen Posted May 24, 2007 Share Posted May 24, 2007 you'd need to store some info in a database and then drag that info onto the page to display it. Do you have any code to start with? Quote Link to comment https://forums.phpfreaks.com/topic/52776-newbie-dynamic-web-page-link/#findComment-260647 Share on other sites More sharing options...
alejandro52 Posted May 24, 2007 Author Share Posted May 24, 2007 I have created the basic web page(as template in dreamweaver).You mean the code of the template?i have done that for the database <?php $connect = mysql_connect('localhost', 'user1', 'testing') or die('Could not connect: ' . mysql_error()); $db = 'test'; mysql_select_db($db) or die('Could not select database ('.$db.') because of : '.mysql_error()); $sql = "SET NAMES utf8 COLLATE utf8_bin"; mysql_query($sql) or die(mysql_error()); $query = 'SELECT * FROM erotiseis ORDER BY id DESC'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); ?> and then in a table print the database <table width="100%" border="0" cellpadding="0" cellspacing="0" class="titles"> <!--DWLayoutTable--> <tr> <td width="106" height="17" align="left" valign="top" class="titles">date</td> <td width="339" align="left" valign="top" class="titles">describition</td> <td width="115" align="left" valign="top" class="titles">more(the link to go to)</td> </tr> <tr> <td height="8"></td> <td></td> <td></td> </tr> <?php while($row = mysql_fetch_row($result)) { echo '<tr>'; echo '<td>' . $row[1] . '</td>'; echo '<td>' . $row[2] . '</td>'; $link=$row[3]; echo '<td>' .'<a href='.$link.'>lkj</a>' . '</td>'; echo '</tr>'; } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/52776-newbie-dynamic-web-page-link/#findComment-260654 Share on other sites More sharing options...
Dragen Posted May 24, 2007 Share Posted May 24, 2007 any php? You'll probably need two pages. The index page which will grab the title and maybe the first 30 characters of the news article, and display them in date order, newest at the top. Then the news page which will display whichever news article is selected. On the index page each article should contain a link.. somthing like: <a href="news.php?article=ARTICLEID">read news</a> where news.php is the display page. On the news.php you'd need the code to read the $_GET['article'] variable and then grab the corresponding data from the database for that article id. Quote Link to comment https://forums.phpfreaks.com/topic/52776-newbie-dynamic-web-page-link/#findComment-260658 Share on other sites More sharing options...
alejandro52 Posted May 24, 2007 Author Share Posted May 24, 2007 So the second page will be an empty page with an empty table in it where the data will be displayed?I can display the empty page, but how do i say to display the the data in the empty table? Quote Link to comment https://forums.phpfreaks.com/topic/52776-newbie-dynamic-web-page-link/#findComment-260659 Share on other sites More sharing options...
Dragen Posted May 24, 2007 Share Posted May 24, 2007 I'm not going to write it for you. You should the data in a database. each article as a row in the database with a unique article id. something like: idtitlecontent 1my news articlecontent of article 2my second news articlecontent of article etc. on the blank page you'd need something like: <?php if(isset($_GET['article']){ $article = $_GET['article']; }else{ echo 'error: no article id found'; exit; } ?> That'll read the article's id from the links on the index page. You'll need to write a mysql query to get all the data from the database where id = $article and then displays it. google mysql query and learn from there. note: make sure your pages are saved with the .php filename NOT .html, .htm etc. Quote Link to comment https://forums.phpfreaks.com/topic/52776-newbie-dynamic-web-page-link/#findComment-260665 Share on other sites More sharing options...
alejandro52 Posted May 25, 2007 Author Share Posted May 25, 2007 how do i pass the information on the next page? I tried to look on google but everyone was saying how to use get with forms. I tried using ahref <?php while($row = mysql_fetch_row($result)) { echo '<tr>'; echo '<td>' . $row[1] . '</td>'; echo '<td>' . $row[2] . '</td>'; $link=$row[3]; echo '<td><a href="window.php?$ID=$row[1]">push me</a></td>'; echo '</tr>'; but what do i have to pass to the new window? I'll make a new connection on the new window(if im not using seesions)and sent it the id number so it can find the article i want and then display it? Quote Link to comment https://forums.phpfreaks.com/topic/52776-newbie-dynamic-web-page-link/#findComment-261452 Share on other sites More sharing options...
alejandro52 Posted May 25, 2007 Author Share Posted May 25, 2007 I also saw that the isset gets the button that was pushed to go at the new page how im going to use it with the link? Quote Link to comment https://forums.phpfreaks.com/topic/52776-newbie-dynamic-web-page-link/#findComment-261459 Share on other sites More sharing options...
Dragen Posted May 25, 2007 Share Posted May 25, 2007 $_GET simply grabs anything after the filename in the link.. if you have a link which is: www.mydomain.com/mypage.php?id=3 if you have: $id = $_GET['id']; that will save the $id variable as the value of the id in the link, which is 3. using your code you'd need to make a slight change: <?php while($row = mysql_fetch_row($result)) { echo '<tr>'; echo '<td>' . $row[1] . '</td>'; echo '<td>' . $row[2] . '</td>'; $link=$row[3]; echo '<td><a href="window.php?ID=' . $row[1] . '">push me</a></td>'; echo '</tr>'; ?> I've just got rid of the $ befor ID as it's not needed and put $row in the proper syntax. That will send you to the page window.php with a $_GET variable of ID with a value of whatever $row[1] is. On window.php you'll need something like I put before: <?php if(isset($_GET['ID']){ $id = $_GET['ID']; }else{ echo 'error: no article id found'; exit; } ?> The above code checks if you have set an id or if window.php has been opened without the ?ID= part. If it's been set it sets the variable id to the value of $_GET['ID'], but if it's not set it throws up an error message. Quote Link to comment https://forums.phpfreaks.com/topic/52776-newbie-dynamic-web-page-link/#findComment-261652 Share on other sites More sharing options...
alejandro52 Posted May 26, 2007 Author Share Posted May 26, 2007 $_GET simply grabs anything after the filename in the link.. if you have a link which is: www.mydomain.com/mypage.php?id=3 if you have: $id = $_GET['id']; that will save the $id variab.... Something else.Can i add the whole article(which can be 10,000 characters long) in the article column or have a link of the article in the article column in the database and then call it from there?I was thinking the second one.If they are both possible which one is better? Quote Link to comment https://forums.phpfreaks.com/topic/52776-newbie-dynamic-web-page-link/#findComment-262006 Share on other sites More sharing options...
Dragen Posted May 26, 2007 Share Posted May 26, 2007 Well you could either have the whole article stored in the database, or if it's that long it might be better to store them in text files, I'm not sure. That'd be up to you. I don't know much about creating and writing/editing text files through php, but I understand it's quite simple. It might be easier just to add it all to the database, but might bog it down a bit.. Then again that's what databases are for lots of information. If storing it in the database you'd just need a simple mysql query to find the row where the article id is equall to the $_GET['ID'], then simply echo the article. Quote Link to comment https://forums.phpfreaks.com/topic/52776-newbie-dynamic-web-page-link/#findComment-262022 Share on other sites More sharing options...
alejandro52 Posted May 26, 2007 Author Share Posted May 26, 2007 Ok, thx a lot for the help and for all the answers. Quote Link to comment https://forums.phpfreaks.com/topic/52776-newbie-dynamic-web-page-link/#findComment-262196 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.